From patchwork Mon Oct 2 12:05:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 147267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1388013vqb; Mon, 2 Oct 2023 05:24:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqD9De/RwBQ6CBZ2IUDQnVAT/2VBWUM0KayhX5VDYPC4OUiZAfmOyOjBML5WArDnR4sgRq X-Received: by 2002:a05:6a20:13d1:b0:15d:607b:5a39 with SMTP id ho17-20020a056a2013d100b0015d607b5a39mr8679274pzc.30.1696249492751; Mon, 02 Oct 2023 05:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696249492; cv=none; d=google.com; s=arc-20160816; b=mGONqhUxbXOJCC1ZiRdkZl06XjJABwyOBdkxBhYkj9DbV6dakDKP/a4Ru82pG50ySn bK52CiFTTz+se5v/fST234b8oCDdyb9phpD+rS8YlyUpaeSTKJuUOjBm+sXEXsHryKYk w/zId4nXWKL9hiF1+smaqg7VSnGfQLXgLevZVLMtFSwpdQA7cKyKjmyXwMB44YaTPuDB JNO1lHzs5DZ3KfMqBN2R/gU5bqQG8RiJ7K/f2bDRHB1SfVfshtDKRkqUz5HB3nALRs6S 52VOJQspoXDHfKVEXp5jBhWczbWSmHFemlB0r62/JFBvyQdw60SKNVCUseoIvPlXXQcp ikcg== 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=aDL5gETzUiP0VzZZCijO3U9Zzi9a1aLBhnH2wBWpEGU=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=KHnfhTU3T6xygyKTyG0cc2MqTvegTbMlBhPB5P4DqXOyn1MjlQFoHWyKolDVV//q6o CYweO30aL6sc+BuftS1x+UbgjQNTR6TPOL0zSQ9vjMbArRvUT1HSs8Ss+DUmEWOds+TI tc7fjzmfwLt0BXnJ+ZCe/uzOE2x0lWZ4WEjleVODGsYa98HVE4bnODmq+x4UT/wuWPJd 4I0/77tr/c+Z/NdhLQ0WHzcoMNWerkaCWS87hInJkLANUgwoadk7gjiIbrfa/hHYi4l2 I6H94r8xNi4VjgB0kZf0eEIO8JDDdNlV9pQYoo3hicsw36ZbdfsJlf88IJ559DwCvxMn dKcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VgnDE4Lc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id kx11-20020a170902f94b00b001c60636e426si21411875plb.432.2023.10.02.05.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 05:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VgnDE4Lc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 1A8C2803FC35; Mon, 2 Oct 2023 05:08:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237182AbjJBMHK (ORCPT + 18 others); Mon, 2 Oct 2023 08:07:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236993AbjJBMGe (ORCPT ); Mon, 2 Oct 2023 08:06:34 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD119D; Mon, 2 Oct 2023 05:06:31 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:9537:67ca:c85e:d0ae]) (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 C3D9C6607325; Mon, 2 Oct 2023 13:06:29 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1696248390; bh=EMKVWITArl2PHuWHDFd/NcTii9pr6T7GjKNa1Tuop1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VgnDE4LcDMcIb3QOGTX80WpnO4h5ZZThD4MlCUz2vh52JAJTkzMUrM1KNh82GuMYi R6RcXiYKNe4CtTF8L0yIfHrO7Q5aeQVo50f9MddD7qCQHM6e/ahGGT7HiRP7wEkQH+ nRsHZGf+Qugk8MtatnA9TPftEeMwhUSAPU/A6KMlECB//iSUMOjHKE6lWAoyLFDy3U QmC4ru17IQ1sEMR+kvNvd84iaLljsryg4AYhVyEFLsvNI8J5zB8VvrrGZ9hu1EPos8 4Hs0B0N1hHG6gFO00+zjBwDKn2lPpa8JCmWxUqvyI/2ToIkSu0Sa78tl10YvvMFPRK 75PRoa9kWMjAQ== 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 v9 10/53] media: dvb-core: Use vb2_get_buffer() instead of directly access to buffers array Date: Mon, 2 Oct 2023 14:05:34 +0200 Message-Id: <20231002120617.119602-11-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002120617.119602-1-benjamin.gaignard@collabora.com> References: <20231002120617.119602-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 05:08:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778646508049733789 X-GMAIL-MSGID: 1778646508049733789 Use vb2_get_buffer() instead of directly access to vb2_buffer buffer array. This could allow to change the type bufs[] field of vb2_buffer structure if needed. 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);