From nobody Sun Nov 10 11:15:02 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF1B1EE0214 for ; Thu, 14 Sep 2023 13:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239120AbjINNdq (ORCPT ); Thu, 14 Sep 2023 09:33:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238993AbjINNdi (ORCPT ); Thu, 14 Sep 2023 09:33:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA261FC0; Thu, 14 Sep 2023 06:33:34 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:36f2:37bd:ccbb:373f]) (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 A6F05660734E; Thu, 14 Sep 2023 14:33:32 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694698413; bh=EpFgbhDUnMMeXI9r0f9hD84Y41WHjCMZ64TZX2CDeks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMvgCnejrmDNkJvdeZxF2yAQx3hIW6x1pFeAj8+xE7tFRADQp8vr2DKbamuYzuMvH F1AeLzLydtRhrlGV4H6bJsX1j/LVA6YxUwFWwmi+tk6GdVTfFid16tXEvIGfDJFYor bYGa5B6uG7rb4/WZGJTWYMYjJD4h36HbYVLe4q1GU/yO2iyHf44d/jgPN6nsyoJEfs MRB8nIH/fsYj/QoilB826O5VhAhBRViUvgTsPtDwG8S+5WBjEJqW5MY0/QeN4vjF+s rMGr2F+66lqhhmUR0qMb2td+yJJJ6t1oSBgzfhrsmYclOJVeNzePagFKbnFPvmGHSI YnYAH1nhH+xPA== 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 Subject: [PATCH v7 03/49] media: videobuf2: Use vb2_buffer instead of index Date: Thu, 14 Sep 2023 15:32:37 +0200 Message-Id: <20230914133323.198857-4-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230914133323.198857-1-benjamin.gaignard@collabora.com> References: <20230914133323.198857-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Directly use vb2_buffer pointer instead of index inside queue array. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 40 ++++++------------- .../media/common/videobuf2/videobuf2-v4l2.c | 30 ++++++++++++-- drivers/media/dvb-core/dvb_vb2.c | 6 +-- include/media/videobuf2-core.h | 16 ++++---- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/medi= a/common/videobuf2/videobuf2-core.c index bedd827c0d9a..5f31b99e3f03 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -649,9 +649,9 @@ static bool __buffers_in_use(struct vb2_queue *q) return false; } =20 -void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb) +void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *p= b) { - call_void_bufop(q, fill_user_buffer, q->bufs[index], pb); + call_void_bufop(q, fill_user_buffer, vb, pb); } EXPORT_SYMBOL_GPL(vb2_core_querybuf); =20 @@ -1485,9 +1485,6 @@ static void vb2_req_unprepare(struct media_request_ob= ject *obj) WARN_ON(!vb->req_obj.req); } =20 -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, - struct media_request *req); - static void vb2_req_queue(struct media_request_object *obj) { struct vb2_buffer *vb =3D container_of(obj, struct vb2_buffer, req_obj); @@ -1502,7 +1499,7 @@ static void vb2_req_queue(struct media_request_object= *obj) * set. We just ignore that, and expect this will be caught the * next time vb2_req_prepare() is called. */ - err =3D vb2_core_qbuf(vb->vb2_queue, vb->index, NULL, NULL); + err =3D vb2_core_qbuf(vb->vb2_queue, vb, NULL, NULL); WARN_ON_ONCE(err && err !=3D -EIO); mutex_unlock(vb->vb2_queue->lock); } @@ -1557,12 +1554,10 @@ unsigned int vb2_request_buffer_cnt(struct media_re= quest *req) } EXPORT_SYMBOL_GPL(vb2_request_buffer_cnt); =20 -int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) +int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void = *pb) { - struct vb2_buffer *vb; int ret; =20 - vb =3D q->bufs[index]; if (vb->state !=3D VB2_BUF_STATE_DEQUEUED) { dprintk(q, 1, "invalid buffer state %s\n", vb2_state_name(vb->state)); @@ -1649,10 +1644,9 @@ static int vb2_start_streaming(struct vb2_queue *q) return ret; } =20 -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, +int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb, struct media_request *req) { - struct vb2_buffer *vb; enum vb2_buffer_state orig_state; int ret; =20 @@ -1661,8 +1655,6 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int i= ndex, void *pb, return -EIO; } =20 - vb =3D q->bufs[index]; - if (!req && vb->state !=3D VB2_BUF_STATE_IN_REQUEST && q->requires_requests) { dprintk(q, 1, "qbuf requires a request\n"); @@ -2239,9 +2231,8 @@ static int __find_plane_by_offset(struct vb2_queue *q= , unsigned long off, } =20 int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - unsigned int index, unsigned int plane, unsigned int flags) + struct vb2_buffer *vb, unsigned int plane, unsigned int flags) { - struct vb2_buffer *vb =3D NULL; struct vb2_plane *vb_plane; int ret; struct dma_buf *dbuf; @@ -2266,13 +2257,6 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, un= signed int type, return -EINVAL; } =20 - if (index >=3D q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); - return -EINVAL; - } - - vb =3D q->bufs[index]; - if (plane >=3D vb->num_planes) { dprintk(q, 1, "buffer plane out of range\n"); return -EINVAL; @@ -2291,20 +2275,20 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, u= nsigned int type, flags & O_ACCMODE); if (IS_ERR_OR_NULL(dbuf)) { dprintk(q, 1, "failed to export buffer %d, plane %d\n", - index, plane); + vb->index, plane); return -EINVAL; } =20 ret =3D dma_buf_fd(dbuf, flags & ~O_ACCMODE); if (ret < 0) { dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n", - index, plane, ret); + vb->index, plane, ret); dma_buf_put(dbuf); return ret; } =20 dprintk(q, 3, "buffer %d, plane %d exported as %d descriptor\n", - index, plane, ret); + vb->index, plane, ret); *fd =3D ret; =20 return 0; @@ -2713,7 +2697,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int= read) * Queue all buffers. */ for (i =3D 0; i < q->num_buffers; i++) { - ret =3D vb2_core_qbuf(q, i, NULL, NULL); + ret =3D vb2_core_qbuf(q, q->bufs[i], NULL, NULL); if (ret) goto err_reqbufs; fileio->bufs[i].queued =3D 1; @@ -2898,7 +2882,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *= q, char __user *data, size_ =20 if (copy_timestamp) b->timestamp =3D ktime_get_ns(); - ret =3D vb2_core_qbuf(q, index, NULL, NULL); + ret =3D vb2_core_qbuf(q, b, NULL, NULL); dprintk(q, 5, "vb2_dbuf result: %d\n", ret); if (ret) return ret; @@ -3001,7 +2985,7 @@ static int vb2_thread(void *data) if (copy_timestamp) vb->timestamp =3D ktime_get_ns(); if (!threadio->stop) - ret =3D vb2_core_qbuf(q, vb->index, NULL, NULL); + ret =3D vb2_core_qbuf(q, vb, NULL, NULL); call_void_qop(q, wait_prepare, q); if (ret || threadio->stop) break; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/medi= a/common/videobuf2/videobuf2-v4l2.c index c7a54d82a55e..697c8a9f98cd 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -667,7 +667,7 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffe= r *b) vb =3D q->bufs[b->index]; ret =3D __verify_planes_array(vb, b); if (!ret) - vb2_core_querybuf(q, b->index, b); + vb2_core_querybuf(q, vb, b); return ret; } EXPORT_SYMBOL(vb2_querybuf); @@ -723,6 +723,7 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs); int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b) { + struct vb2_buffer *vb; int ret; =20 if (vb2_fileio_is_active(q)) { @@ -733,9 +734,15 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_= device *mdev, if (b->flags & V4L2_BUF_FLAG_REQUEST_FD) return -EINVAL; =20 + if (b->index >=3D q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb =3D q->bufs[b->index]; + ret =3D vb2_queue_or_prepare_buf(q, mdev, b, true, NULL); =20 - return ret ? ret : vb2_core_prepare_buf(q, b->index, b); + return ret ? ret : vb2_core_prepare_buf(q, vb, b); } EXPORT_SYMBOL_GPL(vb2_prepare_buf); =20 @@ -803,6 +810,7 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *= mdev, struct v4l2_buffer *b) { struct media_request *req =3D NULL; + struct vb2_buffer *vb; int ret; =20 if (vb2_fileio_is_active(q)) { @@ -810,10 +818,16 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device= *mdev, return -EBUSY; } =20 + if (b->index >=3D q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb =3D q->bufs[b->index]; + ret =3D vb2_queue_or_prepare_buf(q, mdev, b, false, &req); if (ret) return ret; - ret =3D vb2_core_qbuf(q, b->index, b, req); + ret =3D vb2_core_qbuf(q, vb, b, req); if (req) media_request_put(req); return ret; @@ -873,7 +887,15 @@ EXPORT_SYMBOL_GPL(vb2_streamoff); =20 int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb) { - return vb2_core_expbuf(q, &eb->fd, eb->type, eb->index, + struct vb2_buffer *vb; + + if (eb->index >=3D q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb =3D q->bufs[eb->index]; + + return vb2_core_expbuf(q, &eb->fd, eb->type, vb, eb->plane, eb->flags); } EXPORT_SYMBOL_GPL(vb2_expbuf); diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_= vb2.c index 909df82fed33..b322ef179f05 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -360,7 +360,7 @@ int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dm= x_buffer *b) dprintk(1, "[%s] buffer index out of range\n", ctx->name); return -EINVAL; } - vb2_core_querybuf(&ctx->vb_q, b->index, b); + vb2_core_querybuf(&ctx->vb_q, q->bufs[b->index], b); dprintk(3, "[%s] index=3D%d\n", ctx->name, b->index); return 0; } @@ -370,7 +370,7 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_= exportbuffer *exp) struct vb2_queue *q =3D &ctx->vb_q; int ret; =20 - ret =3D vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, exp->index, + ret =3D vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, q->bufs[exp->index= ], 0, exp->flags); if (ret) { dprintk(1, "[%s] index=3D%d errno=3D%d\n", ctx->name, @@ -391,7 +391,7 @@ int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_bu= ffer *b) dprintk(1, "[%s] buffer index out of range\n", ctx->name); return -EINVAL; } - ret =3D vb2_core_qbuf(&ctx->vb_q, b->index, b, NULL); + ret =3D vb2_core_qbuf(&ctx->vb_q, q->bufs[b->index], b, NULL); if (ret) { dprintk(1, "[%s] index=3D%d errno=3D%d\n", ctx->name, b->index, ret); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4b6a9d2ea372..cd3ff1cd759d 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -747,7 +747,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q); /** * vb2_core_querybuf() - query video buffer information. * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @pb: buffer struct passed from userspace. * * Videobuf2 core helper to implement VIDIOC_QUERYBUF() operation. It is c= alled @@ -759,7 +759,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q); * * Return: returns zero on success; an error code otherwise. */ -void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); +void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *p= b); =20 /** * vb2_core_reqbufs() - Initiate streaming. @@ -823,7 +823,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_= memory memory, * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace * to the kernel. * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @pb: buffer structure passed from userspace to * &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver. * @@ -839,13 +839,13 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb= 2_memory memory, * * Return: returns zero on success; an error code otherwise. */ -int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb= ); +int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void = *pb); =20 /** * vb2_core_qbuf() - Queue a buffer from userspace * * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer + * @vb: pointer to struct &vb2_buffer. * @pb: buffer structure passed from userspace to * v4l2_ioctl_ops->vidioc_qbuf handler in driver * @req: pointer to &struct media_request, may be NULL. @@ -867,7 +867,7 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned = int index, void *pb); * * Return: returns zero on success; an error code otherwise. */ -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, +int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb, struct media_request *req); =20 /** @@ -931,7 +931,7 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned in= t type); * @fd: pointer to the file descriptor associated with DMABUF * (set by driver). * @type: buffer type. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @plane: index of the plane to be exported, 0 for single plane queues * @flags: file flags for newly created file, as defined at * include/uapi/asm-generic/fcntl.h. @@ -945,7 +945,7 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned in= t type); * Return: returns zero on success; an error code otherwise. */ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - unsigned int index, unsigned int plane, unsigned int flags); + struct vb2_buffer *vb, unsigned int plane, unsigned int flags); =20 /** * vb2_core_queue_init() - initialize a videobuf2 queue --=20 2.39.2