From patchwork Tue Oct 31 16:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 160208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp364171vqg; Tue, 31 Oct 2023 09:34:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETVGwDayJk5fc4IHRmmZFUQ75KdN608V7nEYOKLgPY58EOTzAzLNZQx1qZMeY5/lYkGXyM X-Received: by 2002:a05:6a00:1883:b0:6bd:d884:df00 with SMTP id x3-20020a056a00188300b006bdd884df00mr15679592pfh.9.1698770041856; Tue, 31 Oct 2023 09:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698770041; cv=none; d=google.com; s=arc-20160816; b=mVcCUkhGWfQD+hkgAz/tabJnEMWWq0EZQ9oV63m9VbjZcA99DGoigYD8U61s6mJMe0 30wnlAz6oVIqlg1Mc249TrI+jB7uYCbu6i7dODELbPvRmfJbq3Tl9ccpuXqME3icclnE jfo0NdgbW0WX1xL/gkUBpv0FhltUlVSsIWgwJpZtS+hd/gV7uAfNQ2Y8XplTa+iL5QQz sa0EK7frWsNr16kr06imYVTUMa116EW+I3vR/JZf4B1yqzMztRphKoXgsaFWzKEloMIg ZUUKHMXLBvlEaD6XeaO3WH9rWFi34F9cqpzFkGP/LnGpVxXioLPKe4rzvSjNUeC0EMhJ JeIg== 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=fhYiqu43kO0n0IvblTJ/hsm3yyVmw0vYbphvRPP598Momk67iqgQKhI8fjNFbR/zTy Sc5IpXHGQ/IFX0pr8wCF9Yhhm2ouGZyJgeAcnyD/yV4HEWs7kSU5aIM4n29otEiw/oVG Ll5pr9zicqHcjScR1Tbnk0jwraXPERjfwCSa2AXVc/Mo9UHNkmZj0zrMKZRU6O4rwmK0 1BpjW32A4UrstGezvKLGT7/mkM7VJH9dwFW2o1Gp85ZCK/Tok7marGFX4IFhrjbTzIaR Xw0h/wZDr4q7k7UD8lg3L2hm51dLvhfgwSvwa107Sam+iixfCgUkupXctxaq3wjQYvGB qdkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="AJdL/D3B"; 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 x2-20020aa79402000000b006be044f21efsi1167468pfo.362.2023.10.31.09.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 09:34:01 -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="AJdL/D3B"; 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 9A3F480BC508; Tue, 31 Oct 2023 09:33:53 -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 S1345214AbjJaQcl (ORCPT + 33 others); Tue, 31 Oct 2023 12:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345650AbjJaQcH (ORCPT ); Tue, 31 Oct 2023 12:32:07 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DD35F1; Tue, 31 Oct 2023 09:31:42 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:c562:2ef4:80c0:92f]) (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 DC8B066073C3; Tue, 31 Oct 2023 16:31:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1698769901; bh=/R1pnW8jfIuOE9V1pOiXWbvwVFtKNqZCCdQZpnNVq6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AJdL/D3BN3Iq1rwhxAMP52DsF7g6nqTXEX6MidFeQ7YvF7KnXRfyRkTnbqFCnxr75 5syvNy5QSP6wFmFjBCRBNmJPgB+N49Z6nKVKACwOU9DxuHsDgd4VEAM09Cz+F6mP/K 8eBHU0Or/egtSXtSKUv8H/88FvwGHiTkcHK7IrUCzSitmK/HO23ZAQc170Dvr9HmMf 8bUDKZmiO9DCvI6B2LmlKRuEkTLK4jeXX2R+VxnX55VaOXYd1CobEeVlw0H5EwUhDL cKBML90kYwHJ9VatjqYDTRGlp4kcvx6JTRx5QmfeIu7B6mbDahp9YHqQ9RPVRHdYr6 jVQzv95iy65EQ== 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 v14 18/56] media: dvb-core: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 31 Oct 2023 17:30:26 +0100 Message-Id: <20231031163104.112469-19-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231031163104.112469-1-benjamin.gaignard@collabora.com> References: <20231031163104.112469-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,T_SCC_BODY_TEXT_LINE 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]); Tue, 31 Oct 2023 09:33:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781289495001214585 X-GMAIL-MSGID: 1781289495001214585 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 Reviewed-by: Andrzej Pietrasiewicz --- 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);