From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Hans de Goede <hansg@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: uvcvideo: Add a stream backpointer in uvc_video_queue
Date: Tue, 24 Mar 2026 00:34:01 +0200 [thread overview]
Message-ID: <20260323223401.GB2329138@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20260318202352.1374443-1-ribalda@chromium.org>
Hi Ricardo,
Thank you for the patch.
On Wed, Mar 18, 2026 at 08:22:36PM +0000, Ricardo Ribalda wrote:
> It is less prone to errors if we add a backpointer to stream from
> struct uvc_video_queue.
>
> Refactor the code.
>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> Tested in real hardware with yavta:
> (console A) # yavta -c /dev/video1
> (console B) # yavta -c /dev/video0
> It would be great if we add it as a follow-up patch to the already
> merged series.
>
> Thanks!
>
> drivers/media/usb/uvc/uvc_driver.c | 2 +-
> drivers/media/usb/uvc/uvc_isight.c | 3 +--
> drivers/media/usb/uvc/uvc_queue.c | 15 ++++++++-------
> drivers/media/usb/uvc/uvcvideo.h | 12 +++---------
> 4 files changed, 13 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index b0ca81d924b6..017b1f4ae3ab 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -2033,7 +2033,7 @@ int uvc_register_video_device(struct uvc_device *dev,
> int ret;
>
> /* Initialize the video buffers queue. */
> - ret = uvc_queue_init(queue, type);
> + ret = uvc_queue_init(stream, queue, type);
> if (ret)
> return ret;
>
> diff --git a/drivers/media/usb/uvc/uvc_isight.c b/drivers/media/usb/uvc/uvc_isight.c
> index ea9dc31dfbad..bb3e13c0d5a6 100644
> --- a/drivers/media/usb/uvc/uvc_isight.c
> +++ b/drivers/media/usb/uvc/uvc_isight.c
> @@ -41,8 +41,7 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
> 0xde, 0xad, 0xfa, 0xce
> };
>
> - struct uvc_streaming *stream = uvc_queue_to_stream(queue,
> - V4L2_BUF_TYPE_VIDEO_CAPTURE);
> + struct uvc_streaming *stream = queue->stream;
> unsigned int maxlen, nbytes;
> u8 *mem;
> int is_header = 0;
> diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> index 89206f761006..3c002c8f442f 100644
> --- a/drivers/media/usb/uvc/uvc_queue.c
> +++ b/drivers/media/usb/uvc/uvc_queue.c
> @@ -78,7 +78,7 @@ static int uvc_queue_setup(struct vb2_queue *vq,
> unsigned int sizes[], struct device *alloc_devs[])
> {
> struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
> - struct uvc_streaming *stream = uvc_queue_to_stream(queue, vq->type);
> + struct uvc_streaming *stream = queue->stream;
> unsigned int size;
>
> switch (vq->type) {
> @@ -112,7 +112,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
>
> if (vb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
> vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
> - uvc_dbg(uvc_queue_to_stream(queue, vb->type)->dev, CAPTURE,
> + uvc_dbg(queue->stream->dev, CAPTURE,
> "[E] Bytes used out of bounds\n");
> return -EINVAL;
> }
> @@ -159,17 +159,16 @@ static void uvc_buffer_finish(struct vb2_buffer *vb)
> {
> struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
> - struct uvc_streaming *stream = uvc_queue_to_stream(queue, vb->type);
> struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
>
> if (vb->state == VB2_BUF_STATE_DONE)
> - uvc_video_clock_update(stream, vbuf, buf);
> + uvc_video_clock_update(queue->stream, vbuf, buf);
> }
>
> static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
> {
> struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
> - struct uvc_streaming *stream = uvc_queue_to_stream(queue, vq->type);
> + struct uvc_streaming *stream = queue->stream;
> int ret;
>
> lockdep_assert_irqs_enabled();
> @@ -196,7 +195,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
> static void uvc_stop_streaming_video(struct vb2_queue *vq)
> {
> struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
> - struct uvc_streaming *stream = uvc_queue_to_stream(queue, vq->type);
> + struct uvc_streaming *stream = queue->stream;
>
> lockdep_assert_irqs_enabled();
>
> @@ -237,10 +236,12 @@ static const struct vb2_ops uvc_meta_queue_qops = {
> .stop_streaming = uvc_stop_streaming_meta,
> };
>
> -int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type)
> +int uvc_queue_init(struct uvc_streaming *stream, struct uvc_video_queue *queue,
> + enum v4l2_buf_type type)
> {
> int ret;
>
> + queue->stream = stream;
> queue->queue.type = type;
> queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
> queue->queue.drv_priv = queue;
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 5ba698d2a23d..0a0c01b2420f 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -331,6 +331,7 @@ struct uvc_buffer {
> #define UVC_QUEUE_DISCONNECTED (1 << 0)
>
> struct uvc_video_queue {
> + struct uvc_streaming *stream;
> struct video_device vdev;
> struct vb2_queue queue;
> struct mutex mutex; /*
> @@ -692,7 +693,8 @@ do { \
> struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
>
> /* Video buffers queue management. */
> -int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type);
> +int uvc_queue_init(struct uvc_streaming *stream, struct uvc_video_queue *queue,
> + enum v4l2_buf_type type);
> void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
> struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
> struct uvc_buffer *buf);
> @@ -703,14 +705,6 @@ static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
> return vb2_is_streaming(&queue->queue);
> }
>
> -static inline struct uvc_streaming *
> -uvc_queue_to_stream(struct uvc_video_queue *queue, unsigned int type)
> -{
> - if (type == V4L2_BUF_TYPE_META_CAPTURE)
> - return container_of(queue, struct uvc_streaming, meta.queue);
> - return container_of(queue, struct uvc_streaming, queue);
> -}
> -
> /* V4L2 interface */
> extern const struct v4l2_ioctl_ops uvc_ioctl_ops;
> extern const struct v4l2_file_operations uvc_fops;
--
Regards,
Laurent Pinchart
prev parent reply other threads:[~2026-03-23 22:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:01 [PATCH 0/3] media: uvcvideo: Improvements for UVC metadata Ricardo Ribalda
2026-03-09 15:01 ` [PATCH 1/3] media: uvcvideo: Enable VB2_DMABUF for metadata stream Ricardo Ribalda
2026-03-16 11:47 ` Hans de Goede
2026-03-18 19:15 ` Laurent Pinchart
2026-03-09 15:01 ` [PATCH 2/3] media: uvcvideo: uvc_queue_to_stream(): Support meta queues Ricardo Ribalda
2026-03-16 11:49 ` Hans de Goede
2026-03-18 19:18 ` Laurent Pinchart
2026-03-09 15:01 ` [PATCH 3/3] media: uvcvideo: Allow userspace to increase the meta buffersize Ricardo Ribalda
2026-03-16 11:53 ` Hans de Goede
2026-03-18 19:22 ` Laurent Pinchart
2026-03-18 19:29 ` Ricardo Ribalda
2026-03-18 19:36 ` Laurent Pinchart
2026-03-16 12:05 ` [PATCH 0/3] media: uvcvideo: Improvements for UVC metadata Hans de Goede
2026-03-18 19:23 ` Laurent Pinchart
2026-03-18 20:22 ` [PATCH] media: uvcvideo: Add a stream backpointer in uvc_video_queue Ricardo Ribalda
2026-03-23 22:34 ` Laurent Pinchart [this message]
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=20260323223401.GB2329138@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=ribalda@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