From patchwork Thu Nov 9 16:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 163468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp555651vqs; Thu, 9 Nov 2023 08:33:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkK3y3uFNUZU+DR+rxANEXxr+87DX+kDBeCqbm1ZoNTTnJ/IQZwzOL0wCtYslTR6qobKAY X-Received: by 2002:a17:90b:4c0b:b0:280:2823:6612 with SMTP id na11-20020a17090b4c0b00b0028028236612mr2023283pjb.35.1699547606035; Thu, 09 Nov 2023 08:33:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699547606; cv=none; d=google.com; s=arc-20160816; b=kWoe7fepzGq8U+D6183cHIQPuYbuJmGyRrJTG0dWwPmtE2pS9rtdBPCtOVoL9Lb4VJ IjUWBdQyfPat/WM8bkR5ZtEupvyLnELicVyEgMtk3WO1l8n4owXI0V3VEheKhodTpYpT FmzQBnrThyFMfy9MMxPud2w0oTF1pX3kFq2JVrMqjtcY1wTISvTscUpN1LlORkCMPjR0 t+9Mzq8WZHZSFl5TCzFdosjCC0zh+orKMMG0F+w+ubX1hei9uGKqdF0vl4GqyWf/rGvu TC6YPW/oPSxvT0fh4Xue9oqoDc723EkG4EMRV9SEm9yA1Ngsbc7WbW6MiD2t3Sq7r+ES J1tw== 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=REQjwdZNT9oDr4RHQoEtlN8v1NdU3UK12kczFgah6DY=; fh=+cz7VFn5lXwyEkr8YqQHlm8vP6/A+SqznlOaRcZfgps=; b=tI4VECQC4ej4aBJxXjslVZLhDoiPKFSby5JA16mLXRi9MLcrdEW0m026ewS8wXwdrC hYZxRZK9z8s2sCUACeI1xoKauoHP7xt9tnSvFecg7NJUnUejIYPt4fg8jdjU1OrFt0uM gYNk8TgcF1GQ8IBpQIeocT5csJWa4V/vD8UvwzdyQruS0ULzE6wtFAYQV/D8lrHLVdIb k0RlxcSP7KSWdEpvA3iLp2OHZt2QXWio4AtZIYVWvOv8Q2p6Ep6FbQYSbzd2zRQfGutd q3UcJA7LxPPlIlBbkkGyS+rTEvrKWtcDL+TYNk1me0/dmTzfHsJtJ7spDaMq+xCGEdST M/1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="muu/4RLh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w4-20020a17090a8a0400b0026f4d1e6940si2038450pjn.160.2023.11.09.08.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 08:33:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="muu/4RLh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 278BB832A757; Thu, 9 Nov 2023 08:33:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235004AbjKIQdL (ORCPT + 31 others); Thu, 9 Nov 2023 11:33:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344140AbjKIQcu (ORCPT ); Thu, 9 Nov 2023 11:32:50 -0500 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 5CF713A85; Thu, 9 Nov 2023 08:32:45 -0800 (PST) Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 E8FF866076AA; Thu, 9 Nov 2023 16:32:42 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1699547564; bh=PTo/lEgMtFohowt4upXDcQZ3buaIbCY7CSCf1Rsf9X4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=muu/4RLhhYIvaytTMJ3ko9445xcwfw9LmwypaWwzn1Mz5l1cxy8Uu/P09WJvFXNF8 vMXULbeVScZg/kSH5VwDDPB2FbBhIgXJtfc4bVKs916Yssye5QbZ5NtF15WZyWFxVk y5CA1IaL3OrKO8ciavZ47JrfyfRjIH2SzLU1/gSSlxzXqB6TbgODXdFcwrprY4LTOL tQbsGYG5QkAwOxfM3MmPlFg9sqYmWMdPMNaN6Bpe+OPJDTfx3XOjPwZ3vK117+ssGF sc7AawLchkPxb89u1RZ57r/aKNG6T4Rf2S7bdD4PP0P6uvXTjs1zMDRS0Z7URWEicK MRxVrBT9NAWXA== 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 , Andrzej Pietrasiewicz , Zhou Peng Subject: [PATCH v15 09/56] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 9 Nov 2023 17:29:21 +0100 Message-Id: <20231109163008.179152-10-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231109163008.179152-1-benjamin.gaignard@collabora.com> References: <20231109163008.179152-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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]); Thu, 09 Nov 2023 08:33:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782104830740433650 X-GMAIL-MSGID: 1782104830740433650 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 CC: Ming Qian CC: Zhou Peng --- 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],