drivers/media/usb/uvc/uvc_isight.c | 3 ++- drivers/media/usb/uvc/uvc_metadata.c | 9 +++++++-- drivers/media/usb/uvc/uvc_queue.c | 18 ++++++++---------- drivers/media/usb/uvc/uvcvideo.h | 7 +++++-- 4 files changed, 22 insertions(+), 15 deletions(-)
This series introduces some improvements for UVC metadata:
- Allow bigger sizes of metadata.
- Refactor the code to avoid invalid pointer arithmetic.
- Add support for DMABUF
Cheers!
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
Ricardo Ribalda (3):
media: uvcvideo: Enable VB2_DMABUF for metadata stream
media: uvcvideo: uvc_queue_to_stream(): Support meta queues
media: uvcvideo: Allow userspace to increase the meta buffersize
drivers/media/usb/uvc/uvc_isight.c | 3 ++-
drivers/media/usb/uvc/uvc_metadata.c | 9 +++++++--
drivers/media/usb/uvc/uvc_queue.c | 18 ++++++++----------
drivers/media/usb/uvc/uvcvideo.h | 7 +++++--
4 files changed, 22 insertions(+), 15 deletions(-)
---
base-commit: a7da7fb57f2a787412da1a62292a17fa00fbfbdf
change-id: 20260309-uvc-metadata-dmabuf-b98359eec8dd
Best regards,
--
Ricardo Ribalda <ribalda@chromium.org>
Hi, On 9-Mar-26 4:01 PM, Ricardo Ribalda wrote: > This series introduces some improvements for UVC metadata: > > - Allow bigger sizes of metadata. > - Refactor the code to avoid invalid pointer arithmetic. > - Add support for DMABUF > > Cheers! > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Thank you. This entire series seems simple/safe enough and looks good to me from a review pov, so I've pushed this to uvc/for-next now. While it also rebasing uvc/for-next on top of the latest media-committers/next . Regards, Hans > --- > Ricardo Ribalda (3): > media: uvcvideo: Enable VB2_DMABUF for metadata stream > media: uvcvideo: uvc_queue_to_stream(): Support meta queues > media: uvcvideo: Allow userspace to increase the meta buffersize > > drivers/media/usb/uvc/uvc_isight.c | 3 ++- > drivers/media/usb/uvc/uvc_metadata.c | 9 +++++++-- > drivers/media/usb/uvc/uvc_queue.c | 18 ++++++++---------- > drivers/media/usb/uvc/uvcvideo.h | 7 +++++-- > 4 files changed, 22 insertions(+), 15 deletions(-) > --- > base-commit: a7da7fb57f2a787412da1a62292a17fa00fbfbdf > change-id: 20260309-uvc-metadata-dmabuf-b98359eec8dd > > Best regards,
On Mon, Mar 16, 2026 at 01:05:30PM +0100, Hans de Goede wrote: > On 9-Mar-26 4:01 PM, Ricardo Ribalda wrote: > > This series introduces some improvements for UVC metadata: > > > > - Allow bigger sizes of metadata. > > - Refactor the code to avoid invalid pointer arithmetic. > > - Add support for DMABUF > > > > Cheers! > > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > > Thank you. > > This entire series seems simple/safe enough and looks good to me > from a review pov, so I've pushed this to uvc/for-next now. I'd like a small change in 2/3. Ricardo, if you submit a new version of 2/3, I can merge it and handle the rebase. > While it also rebasing uvc/for-next on top of the latest > media-committers/next . > > > --- > > Ricardo Ribalda (3): > > media: uvcvideo: Enable VB2_DMABUF for metadata stream > > media: uvcvideo: uvc_queue_to_stream(): Support meta queues > > media: uvcvideo: Allow userspace to increase the meta buffersize > > > > drivers/media/usb/uvc/uvc_isight.c | 3 ++- > > drivers/media/usb/uvc/uvc_metadata.c | 9 +++++++-- > > drivers/media/usb/uvc/uvc_queue.c | 18 ++++++++---------- > > drivers/media/usb/uvc/uvcvideo.h | 7 +++++-- > > 4 files changed, 22 insertions(+), 15 deletions(-) > > --- > > base-commit: a7da7fb57f2a787412da1a62292a17fa00fbfbdf > > change-id: 20260309-uvc-metadata-dmabuf-b98359eec8dd -- Regards, Laurent Pinchart
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>
---
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;
--
2.53.0.983.g0bb29b3bc5-goog
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
© 2016 - 2026 Red Hat, Inc.