public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
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 <benjamin.gaignard@collabora.com>
Subject: [PATCH v6 08/18] media: visl: Use vb2_get_buffer() instead of directly access to buffers array
Date: Fri,  1 Sep 2023 14:44:04 +0200	[thread overview]
Message-ID: <20230901124414.48497-9-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20230901124414.48497-1-benjamin.gaignard@collabora.com>

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 <benjamin.gaignard@collabora.com>
---
 drivers/media/test-drivers/visl/visl-dec.c | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/media/test-drivers/visl/visl-dec.c b/drivers/media/test-drivers/visl/visl-dec.c
index 318d675e5668..ba20ea998d19 100644
--- a/drivers/media/test-drivers/visl/visl-dec.c
+++ b/drivers/media/test-drivers/visl/visl-dec.c
@@ -290,13 +290,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run)
 	for (i = 0; i < out_q->num_buffers; i++) {
 		char entry[] = "index: %u, state: %s, request_fd: %d, ";
 		u32 old_len = len;
-		char *q_status = visl_get_vb2_state(out_q->bufs[i]->state);
+		struct vb2_buffer *vb2;
+		char *q_status;
+
+		vb2 = vb2_get_buffer(out_q, i);
+		if (!vb2)
+			continue;
+
+		q_status = visl_get_vb2_state(vb2->state);
 
 		len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len,
 				 entry, i, q_status,
-				 to_vb2_v4l2_buffer(out_q->bufs[i])->request_fd);
+				 to_vb2_v4l2_buffer(vb2)->request_fd);
 
-		len += visl_fill_bytesused(to_vb2_v4l2_buffer(out_q->bufs[i]),
+		len += visl_fill_bytesused(to_vb2_v4l2_buffer(vb2),
 					   &buf[len],
 					   TPG_STR_BUF_SZ - len);
 
@@ -342,13 +349,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run)
 	len = 0;
 	for (i = 0; i < cap_q->num_buffers; i++) {
 		u32 old_len = len;
-		char *q_status = visl_get_vb2_state(cap_q->bufs[i]->state);
+		struct vb2_buffer *vb2;
+		char *q_status;
+
+		vb2 = vb2_get_buffer(cap_q, i);
+		if (!vb2)
+			continue;
+
+		q_status = visl_get_vb2_state(vb2->state);
 
 		len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len,
 				 "index: %u, status: %s, timestamp: %llu, is_held: %d",
-				 cap_q->bufs[i]->index, q_status,
-				 cap_q->bufs[i]->timestamp,
-				 to_vb2_v4l2_buffer(cap_q->bufs[i])->is_held);
+				 vb2->index, q_status,
+				 vb2->timestamp,
+				 to_vb2_v4l2_buffer(vb2)->is_held);
 
 		tpg_gen_text(&ctx->tpg, basep, line++ * line_height, 16, &buf[old_len]);
 		frame_dprintk(ctx->dev, run->dst->sequence, "%s", &buf[old_len]);
-- 
2.39.2


  parent reply	other threads:[~2023-09-01 12:44 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 12:43 [PATCH v6 00/18] Add DELETE_BUF ioctl Benjamin Gaignard
2023-09-01 12:43 ` [PATCH v6 01/18] media: videobuf2: Rework offset 'cookie' encoding pattern Benjamin Gaignard
2023-09-01 12:43 ` [PATCH v6 02/18] media: videobuf2: Stop spamming kernel log with all queue counter Benjamin Gaignard
2023-09-04 15:17   ` Hans Verkuil
2023-09-01 12:43 ` [PATCH v6 03/18] media: videobuf2: Use vb2_buffer instead of index Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 04/18] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 05/18] media: mediatek: jpeg: " Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 06/18] media: mediatek: vdec: " Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 07/18] media: sti: hva: " Benjamin Gaignard
2023-09-01 12:44 ` Benjamin Gaignard [this message]
2023-09-01 12:44 ` [PATCH v6 09/18] media: atomisp: " Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 10/18] media: videobuf2: Access vb2_queue bufs array through helper functions Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 11/18] media: videobuf2: Be more flexible on the number of queue stored buffers Benjamin Gaignard
2023-09-04 11:24   ` Hans Verkuil
2023-09-04 11:46     ` Benjamin Gaignard
2023-09-04 14:09       ` Hans Verkuil
2023-09-04 15:05         ` Hans Verkuil
2023-09-04 15:19   ` Hans Verkuil
2023-09-01 12:44 ` [PATCH v6 12/18] media: verisilicon: Refactor postprocessor to store more buffers Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 13/18] media: verisilicon: Store chroma and motion vectors offset Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 14/18] media: verisilicon: vp9: Use destination buffer height to compute chroma offset Benjamin Gaignard
2023-09-10 13:21   ` Jernej Škrabec
2023-09-11  8:55     ` Benjamin Gaignard
2023-09-11 16:36       ` Jernej Škrabec
2023-09-12  8:41         ` Benjamin Gaignard
2023-09-12 15:26           ` Nicolas Dufresne
2023-09-12 15:51           ` Jernej Škrabec
2023-09-01 12:44 ` [PATCH v6 15/18] media: verisilicon: postproc: Fix down scale test Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 16/18] media: verisilicon: vp9: Allow to change resolution while streaming Benjamin Gaignard
2023-09-01 12:44 ` [PATCH v6 17/18] media: v4l2: Add DELETE_BUFS ioctl Benjamin Gaignard
2023-09-05  8:17   ` Hans Verkuil
2023-09-05  8:43     ` Hans Verkuil
2023-09-05 14:28     ` Benjamin Gaignard
2023-09-05 14:37       ` Hans Verkuil
2023-09-01 12:44 ` [PATCH v6 18/18] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2023-09-04 15:23 ` [PATCH v6 00/18] Add DELETE_BUF ioctl Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901124414.48497-9-benjamin.gaignard@collabora.com \
    --to=benjamin.gaignard@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@kernel.org \
    --cc=ming.qian@nxp.com \
    --cc=nicolas.dufresne@collabora.com \
    --cc=p.zabel@pengutronix.de \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox