From patchwork Tue Oct 17 14:47:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 154346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4188963vqb; Tue, 17 Oct 2023 07:52:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEykiX5Glv4QJEEtxSINyuvBtQ2mAZ0BPamwNXEl6YLJO6eoaVs0zbirMJG/7Xb8P564WHJ X-Received: by 2002:a17:902:f154:b0:1bf:349f:b85c with SMTP id d20-20020a170902f15400b001bf349fb85cmr2586018plb.1.1697554356184; Tue, 17 Oct 2023 07:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697554356; cv=none; d=google.com; s=arc-20160816; b=y2Pyy0xKgaU+E9cEO2jOp3MonR2t0C6r519LcRTYiF9Zw/hC8LK9lHyxz8Q6/rylKl 9OUJBBJDux0C24xNPz9SpmGVTIk4CMG/CA45iTF4XmuOYsHgYMWJR9JUdX6IDtrWgZL4 9m/l1USymQkjBxQoMUXXeL2JBGGr68u7pKHg7dvrsPoz4IvpNEQsjqiKPpG+jFLpSIPQ 4dJKBiT6g5N1iawvuALeMxlrgDfjt/uVZKMmAFHMOkkFx2jkkHT5q57C3X8bfWId/Ard R1OPaSrv9L5MNRfPeCVkSp8Fh/CSa6XRtKHPLEh/W6GcyYeYR3I9OUGNMGUkFLf2YEnT mUMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rssmHwRaLIgaYrDGGoiR2bvUGHmWTIHsQMhsS5T9D0o=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=Feb6j1lEhm5HkyOYBvYCCP/GrJ++z/ZDScjReVuD7R/a+8dMb6SHrxA3xugywac245 hJxvgIm+qwW5TGWvm6Y2B13u+Od1AtovbTqXUe/1umVbsbTykPDFJGqNkbiMI71UEi0N dlosBLAlvBv6/I2l6OCYmy4qDCCInq87PrfRt+pBIyPxCsKkxZZgR0nRZFDrTpemhOdO 1dLvD1X1pNPpMCmCWl8Xii1nXbQnVLhcgmF68DUfiejy9IpWcV4WI02TE0UXmUIqnQ6i 8xattSfnk59i8y0Z1m4qtgkAI2PAS4RtyxDVbP0o4yoanrlmb/PTGJByXmaudfGBJ5Wu gtJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="Z9F2JI/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id g4-20020a170902740400b001bf0916b665si1828469pll.393.2023.10.17.07.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="Z9F2JI/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CACE28088A67; Tue, 17 Oct 2023 07:52:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344358AbjJQOua (ORCPT + 20 others); Tue, 17 Oct 2023 10:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344206AbjJQOsX (ORCPT ); Tue, 17 Oct 2023 10:48:23 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 320A5100; Tue, 17 Oct 2023 07:48:14 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7205:da49:a7e8:59f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id A10F46607331; Tue, 17 Oct 2023 15:48:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697554093; bh=/R1pnW8jfIuOE9V1pOiXWbvwVFtKNqZCCdQZpnNVq6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9F2JI/WXF7yHwpusSAVWfFe1ysa+W/k/r6V08+hBvV+pEz4464hDx49g7nMWvf7r y68ewAR6BYPcHLfhM6VSDCN7t/zruLDYsq67Rp7SEJaHYdQBONG9KxiJlcFTJYDcag e0jeIdWRNI6w5fj9MKRZaOAfEV6IGC8FAF5tny4eOqoFitJcomd2ox7Z2aXRWEhbCY okkLJiVpYOlIuxmvMg4gaEgm+RRCWi6CYQaCUrUbjB8A5Hd0WwguHg322DuSsIZ62u mmJxtOkl8zj2WDuJWp6jBVUFTcroudLt9vAoOymAAtGx7lx9Iw2XrpUR/3y9OVxswP QYeeyIRLpyaWA== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v12 18/56] media: dvb-core: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 17 Oct 2023 16:47:18 +0200 Message-Id: <20231017144756.34719-19-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017144756.34719-1-benjamin.gaignard@collabora.com> References: <20231017144756.34719-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 07:52:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780014756128389098 X-GMAIL-MSGID: 1780014756128389098 Use vb2_get_buffer() instead of direct access to the vb2_queue bufs array. This allows us to change the type of the bufs in the future. After each call to vb2_get_buffer() we need to be sure that we get a valid pointer so check the return value of all of them. Signed-off-by: Benjamin Gaignard --- drivers/media/dvb-core/dvb_vb2.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index b322ef179f05..3a966fdf814c 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -355,12 +355,13 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) { struct vb2_queue *q = &ctx->vb_q; + struct vb2_buffer *vb2 = vb2_get_buffer(q, b->index); - if (b->index >= q->num_buffers) { - dprintk(1, "[%s] buffer index out of range\n", ctx->name); + if (!vb2) { + dprintk(1, "[%s] invalid buffer index\n", ctx->name); return -EINVAL; } - vb2_core_querybuf(&ctx->vb_q, q->bufs[b->index], b); + vb2_core_querybuf(&ctx->vb_q, vb2, b); dprintk(3, "[%s] index=%d\n", ctx->name, b->index); return 0; } @@ -385,13 +386,14 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp) int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) { struct vb2_queue *q = &ctx->vb_q; + struct vb2_buffer *vb2 = vb2_get_buffer(q, b->index); int ret; - if (b->index >= q->num_buffers) { - dprintk(1, "[%s] buffer index out of range\n", ctx->name); + if (!vb2) { + dprintk(1, "[%s] invalid buffer index\n", ctx->name); return -EINVAL; } - ret = vb2_core_qbuf(&ctx->vb_q, q->bufs[b->index], b, NULL); + ret = vb2_core_qbuf(&ctx->vb_q, vb2, b, NULL); if (ret) { dprintk(1, "[%s] index=%d errno=%d\n", ctx->name, b->index, ret);