media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers...
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 9 Nov 2023 16:29:23 +0000 (17:29 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 23 Nov 2023 10:59:26 +0000 (11:59 +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: Bin Liu <bin.liu@mediatek.com>
CC: Matthias Brugger <matthias.bgg@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c

index 7194f88edc0fb41c037b7fe91a80f5df6b755b03..73a063b1569b7e707328b096fc6996112b25338d 100644 (file)
@@ -598,12 +598,11 @@ static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
                goto end;
 
        vq = v4l2_m2m_get_vq(fh->m2m_ctx, buf->type);
-       if (buf->index >= vq->num_buffers) {
-               dev_err(ctx->jpeg->dev, "buffer index out of range\n");
+       vb = vb2_get_buffer(vq, buf->index);
+       if (!vb) {
+               dev_err(ctx->jpeg->dev, "buffer not found\n");
                return -EINVAL;
        }
-
-       vb = vq->bufs[buf->index];
        jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
        jpeg_src_buf->bs_size = buf->m.planes[0].bytesused;