From patchwork Wed Sep 27 15:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 145531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2828563vqu; Wed, 27 Sep 2023 11:45:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELeIO9Qwd8vfKLocxB2jlb17KFaERuDJ4+HuQ4w8SIjMgVruVCYKCy0jJblpj4BPNARIPf X-Received: by 2002:a5b:502:0:b0:d07:7a3e:1ab with SMTP id o2-20020a5b0502000000b00d077a3e01abmr2601383ybp.50.1695840346925; Wed, 27 Sep 2023 11:45:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695840346; cv=none; d=google.com; s=arc-20160816; b=0JB9WUwCgXzUpajvmU7dLk9a780ALU+ztj5YWRltdyWF2EmNCoShpRjiAhd1JsIgmq aXPhQGBNDfuUsh8LLqQRvO4O82rNS/MG3/HeLJJ1+txYKeAhJNEVgESe6q37lebRKKqD 9LfCqRi3pvlgsph7ibbeUYdiB9b2vxkOBSJ5Pr6e9nBfTFgxWxyB8L8Nje3JQltj0ucW hWVJn37cff/GZFgviom9qiiUZZq7490iOBM4sN4CUHyfvq6xnPe96JzoVeKICxXKSLfI ouJm/u3G3xnCPOa2LihppoZA3yU0T4ucCx9unaObfYvEAqZK8L/w7kMHpTA6vTy/F8SU rg7Q== 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=x5Wod2segP2UVAPykjwVcUjv6L5HIwvf3XPt0lx7AeLwt6RZbg6HqMJfq7Gi2Z0dx1 7dIEYiqZmCZtX+jIOTJ7g2epSVlBRq1DvEX6w+MPewgNrkBZP7KVI7iPAR2Q4UuU74Bk JjdtnOHY2osJdOaYnzq45PzW/tPq+Rfg2+3j4cUsKktE0Sg7K3F8Go9GIU5AGHYFdbEB IoZVDpo1oMVKfHO122MSnJNrLtDe1eWyfboAVgGAGC8H1+oqdITAlxfi+dnNynZrlykC jZbod2aFHUXpEa9WSwn0IGdpjTYamv3rgeEbGHbN+Ra/ABdoh6zIpnmu8TxUvIeL2ajg xU8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TCVzKYNE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l10-20020a65560a000000b00565ecd01399si16540831pgs.783.2023.09.27.11.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:45:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TCVzKYNE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 6198A8119077; Wed, 27 Sep 2023 08:37:24 -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 S232711AbjI0Pgd (ORCPT + 19 others); Wed, 27 Sep 2023 11:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbjI0PgP (ORCPT ); Wed, 27 Sep 2023 11:36:15 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4725419A; Wed, 27 Sep 2023 08:36:13 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:672:46bd:3ec7:6cdf]) (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 9ED936607337; Wed, 27 Sep 2023 16:36:11 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695828972; bh=EMKVWITArl2PHuWHDFd/NcTii9pr6T7GjKNa1Tuop1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TCVzKYNE4Wnb4NkghJe3VZhRfV+u+zHYIQXfj3xeN7mfbf1sAxiZZmnwR5B6iEZor X/maYWBGaq17bh52pa7d2fOcT2w9owWsHlqa6XXqSJ565cYkGRFqJJK/HV4/enrPzY CIfnefqkYRkrGAepxiGHZD494uL28cRqhx7BdQe/B3M2y+jvZKk2q5bzJHgJlXHnBp Szd/HonJ87kYgs4vhyVB0QhdQ+NEAsNIAHIjn/m43k6jTuO3ppkB1xV871+ye57k24 7BXloLTvwRJKiFQi+6W9uL8MGzZ+P5LcnD0Aeyc/mOF/09Hm+BDqPVwcXbjY5SJHhO 8eONpC4U3YPSQ== 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 v8 10/53] media: dvb-core: Use vb2_get_buffer() instead of directly access to buffers array Date: Wed, 27 Sep 2023 17:35:15 +0200 Message-Id: <20230927153558.159278-11-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927153558.159278-1-benjamin.gaignard@collabora.com> References: <20230927153558.159278-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]); Wed, 27 Sep 2023 08:37:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778217487686429294 X-GMAIL-MSGID: 1778217487686429294 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);