media: visl: Use vb2_get_buffer() instead of directly access to buffers array
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 9 Nov 2023 16:34:31 +0000 (17:34 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 23 Nov 2023 11:06:22 +0000 (12:06 +0100)
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 <benjamin.gaignard@collabora.com>
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
CC: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/test-drivers/visl/visl-dec.c

index 318d675e56689a33401ccca2736d7c284d3ed07d..ba20ea998d19fb61f48641733bb779529255e76f 100644 (file)
@@ -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]);