From patchwork Mon Oct 2 12:05:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 147281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1406617vqb; Mon, 2 Oct 2023 06:00:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNeUz7FvkevCixHJZ2/G5WWh84vB5d01H1PspFMArTezcCb/8KNcvRxnyibKqMag3008+h X-Received: by 2002:a05:6830:1e66:b0:6b9:a926:4a12 with SMTP id m6-20020a0568301e6600b006b9a9264a12mr11673757otr.28.1696251623651; Mon, 02 Oct 2023 06:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696251623; cv=none; d=google.com; s=arc-20160816; b=fo7NRWd/Ua/0aTgAM6klHmBorDXP7UQkWeNKfItbe8fXr3PPNHfy6JH6b/bs7KckzJ qLRFpJv/8hWGLFd+qEHDqVAIVwc+Oo1VDPeb6O7fVrZw3j5/5Ff7+Xgm9ZbQP3rR2ixt xVp+6fqMGT+iN83OM8XGGYdCRrQibJIHQZkaiDwTMsE/0gW18f0yRld8gua47cgoJnQe 8ImllMVqA/TwvkK8gUqeC9h9rSDaDXrUGlz8zsiZB9/U2Kofbi9NjntYxXPIyjuIoyoH HzQEbUh6Kk2hWLwCfWZAygnKNtLhgyrPUlJT/7+CstYETrC0PkcrivZGyvle6jNYRdnJ yIgg== 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=mp1KeUwXEPeyi7FaB/qpZlqFp0j0IcgZ40cl1bA/YGw=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=fGTXfrbRxmakXPsEZwD5vdn6hQVlAtOwAgQ29OTknclOvO0OWjUwuPeDDJ9x6tOeA9 sCiqt//q+GpFCDZO3Wa8y75SYl8+mKR3DSyp+JIKehqsDP3oKpQ1MQNzl+iXnncRrXkn wysr/8g3rBWIolmhfTHxl2XkkiACrxqrDiM+x26dX9grETZJS6gPFke+GGmDDMVkw8mT dbiU6qEFtoveKKIZNSPQufdzxU/X51mnyep8p7bS+1SHIAgzfzCeY0dNibB/GaXWLOV2 532rbcReaK4vIpS8X/SfvrMFQXYYyOmpm9FE9W3AaYGwhsd4RZSu/v3zC3EFVPJY9F+9 JqUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="giuIe/fV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id a193-20020a6390ca000000b00578b79c785bsi7733818pge.217.2023.10.02.06.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:00:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="giuIe/fV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 99FC68129AEF; Mon, 2 Oct 2023 05:07:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236943AbjJBMGw (ORCPT + 18 others); Mon, 2 Oct 2023 08:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236957AbjJBMGb (ORCPT ); Mon, 2 Oct 2023 08:06:31 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BB5FD8; Mon, 2 Oct 2023 05:06:28 -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 8E75666072FB; Mon, 2 Oct 2023 13:06:26 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1696248387; bh=swS7yYiqBxggjIra2XX2pXDY4PPq3f683TK0rKa6DhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=giuIe/fVSLygz4HErc6sFwbwJmDnvrm52UiCkx/M2fccRfO+Ne0i+/neDDX39GxNa KfVc3COaAoRLhuBm+BIKJ4NznCR0J0M4IFn247wArNNfQMouLhriiuR4CwYdsVJEmy T6sGr47TfKy/1+xLr38gwF7rvzU0NtGYvT5olCNNaO6QyoKEqXUziy/QI19UEriG0L ELooCGI0b7wmeddY7d5sPc4c6SQ6RFr/Nw4WKaiHriBeRJCEw2msFICeRCaKNCELEK mzK/yFia3472lzjIY7nkpfqvsSPFHVrKUFveTRI+Jj4WeNutHFdMvM/WOA0HItc3Zp t/wxBw5fWS8kQ== 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 04/53] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Date: Mon, 2 Oct 2023 14:05:28 +0200 Message-Id: <20231002120617.119602-5-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 05:07:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778648742339414120 X-GMAIL-MSGID: 1778648742339414120 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/platform/amphion/vpu_dbg.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c index 982c2c777484..a462d6fe4ea9 100644 --- a/drivers/media/platform/amphion/vpu_dbg.c +++ b/drivers/media/platform/amphion/vpu_dbg.c @@ -140,11 +140,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "output [%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state], @@ -155,11 +162,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "capture[%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state],