From patchwork Tue Oct 17 14:47:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 154320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4187310vqb; Tue, 17 Oct 2023 07:49:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyAAaKNqVFOq8yNLAi5X3WoLG9irGMXOu9NufKkWV5xcI1SXjRp2ke5a970ffKQ+d0qbnR X-Received: by 2002:a05:6a20:c182:b0:15d:6fd3:8e74 with SMTP id bg2-20020a056a20c18200b0015d6fd38e74mr2572817pzb.3.1697554186422; Tue, 17 Oct 2023 07:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697554186; cv=none; d=google.com; s=arc-20160816; b=bYnoakhqdF+DAKhcfka/cSz1Mc/u6Xl/NFPIPbNjw1TQrbsSDWyLLvm9vbxWfQoYkx eTi6GASQ2KuVa79zYsNJ8+K+A/CCGguDT7SZxQbm+j1ozTVgV9D59eReFsq+EOKyA/WG ZTNBmQdd7iwnLOJ0sKPSB4hQ/mbbr0mpcXEvmzscOe8mIQlDaPrkWE9JvTvZS8wMHR/g eokkN3WWByBVpDKMdM3hVVav6iPNBMxASa0VVA6LN3fHfDOqFLiBPY7kxqjbESjpxvK8 TnrIKOhN48RLZmcNEnWu/CWEoHvIm6f3goEoCWmaaaX7VvbmGPzVhVgx/k5XmS4qlUYI CpHg== 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=dlNPY6ibXmdkraUjakRUfz9D8ble9LZN70JvmimE7r4=; fh=YhVWgOX82fKLE5M+MoEX/CwrdcPd8SQ1dctjbZBk3rU=; b=Kab/6pfEQSFoBc4x2v0U+5wcvtAycsSQWxYvOTOyo0kO8e+TIAj2DsUskmuBJcK5/l yHopaeMGUgzDQj8m5+ssv3Cqr9PFCDOlkl81ILZKTHk5YehCuKVXlSQPmII/6M+6KjQR 1BHTR/Aa1Ft388c2Ua+aAQ5UBD1xDmpBxYYOsombQwwaUH7xFfDs/1NPYobMquPVLu6J 28OkoEQh2XZ2gePu6SGdVOpZAQOjp/3stWz/a1wQHewek4LkkO+vR8mDu6wor3xDG6uR OPlxz5zyW2S+fHlGvGpMNtaAg9lRjPh6NMEZtORCSt7kTIwV/EVE2KWvIAO1Bc0inqFB qVTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bZUc9Y7S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l5-20020a170903120500b001c75866c987si1963689plh.584.2023.10.17.07.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:49:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bZUc9Y7S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id C45878044374; Tue, 17 Oct 2023 07:49:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344351AbjJQOsh (ORCPT + 20 others); Tue, 17 Oct 2023 10:48:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344135AbjJQOsL (ORCPT ); Tue, 17 Oct 2023 10:48:11 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AECCFA; Tue, 17 Oct 2023 07:48:09 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7205:da49:a7e8:59f8]) (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 BFC0B660732A; Tue, 17 Oct 2023 15:48:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697554088; bh=FY7GH0xZdlXO2pRrzaejblo22FLeSWf56n9mo0hrqhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZUc9Y7SvA5unAnAFhBLlfrD4b/UsnNPqJre51LLMtkk9b/SNUAaiyng2Ih4MEAvt JeqtJQgI2gtWTu7Z2z3xZnSgJWyQO4gUEq16nJ7V+xGXNajj/3+bHBuvjTWP0brwwN gEvaL61W0iVQUWiuq7FC/KNzGQYZ+y+Gfc7LLo/9UHA7rMAoKGAlZNsPJK0glD0pkV 5OsZNuhKhU4FmPVKnTZ9SdSTABXjqGTOm5LGwA7w1LUwi6c8p29yFzi5CkcNwaptER RoifIh0vhWNCaS44PD/7tHKuTPv1hsMzncC3GA6NPoBtv72DdIYQkQUS95qxW4ogFn jKg/b3zaMoJpA== 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 , Zhou Peng Subject: [PATCH v12 09/56] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 17 Oct 2023 16:47:09 +0200 Message-Id: <20231017144756.34719-10-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017144756.34719-1-benjamin.gaignard@collabora.com> References: <20231017144756.34719-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 07:49:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780014578812219950 X-GMAIL-MSGID: 1780014578812219950 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 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],