From: Hans de Goede <hansg@kernel.org>
To: Ricardo Ribalda <ribalda@chromium.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] media: uvcvideo: Avoid partial metadata buffers
Date: Mon, 11 May 2026 15:29:06 +0200 [thread overview]
Message-ID: <9ac8787a-b7ba-4f84-a17c-4c1440cabdac@kernel.org> (raw)
In-Reply-To: <20260417-uvc-meta-partial-v2-2-31d274af7d2d@chromium.org>
Hi,
On 17-Apr-26 07:19, Ricardo Ribalda wrote:
> If the metadata queue that is empty receives a new buffer while we are
> in the middle of processing a frame, the first metadata buffer will
> contain partial information.
>
> Avoid this by tracking the state of the metadata buffer and making sure
> that it is in sync with the data buffer.
>
> Now that we are at it, make sure that we skip buffers of size 1 or 0.
> They are not allowed by the spec... but it is a simple check to add and
> better be safe than sorry.
>
> Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_video.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 5d45c74c6041..cd77ca6f8136 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1149,7 +1149,9 @@ static void uvc_video_stats_stop(struct uvc_streaming *stream)
> * uvc_video_decode_end will never be called with a NULL buffer.
> */
> static int uvc_video_decode_start(struct uvc_streaming *stream,
> - struct uvc_buffer *buf, const u8 *data, int len)
> + struct uvc_buffer *buf,
> + struct uvc_buffer *meta_buf,
> + const u8 *data, int len)
> {
> u8 header_len;
> u8 fid;
> @@ -1278,6 +1280,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
>
> /* TODO: Handle PTS and SCR. */
> buf->state = UVC_BUF_STATE_ACTIVE;
> + if (meta_buf)
> + meta_buf->state = UVC_BUF_STATE_ACTIVE;
> }
>
> stream->last_fid = fid;
> @@ -1435,7 +1439,7 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> ktime_t time;
> const u8 *scr;
>
> - if (!meta_buf || length == 2)
> + if (length <= 2 || !meta_buf || meta_buf->state != UVC_BUF_STATE_ACTIVE)
> return;
>
> has_pts = mem[1] & UVC_STREAM_PTS;
> @@ -1552,7 +1556,7 @@ static void uvc_video_decode_isoc(struct uvc_urb *uvc_urb,
> /* Decode the payload header. */
> mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
> do {
> - ret = uvc_video_decode_start(stream, buf, mem,
> + ret = uvc_video_decode_start(stream, buf, meta_buf, mem,
> urb->iso_frame_desc[i].actual_length);
> if (ret == -EAGAIN)
> uvc_video_next_buffers(stream, &buf, &meta_buf);
> @@ -1601,7 +1605,8 @@ static void uvc_video_decode_bulk(struct uvc_urb *uvc_urb,
> */
> if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) {
> do {
> - ret = uvc_video_decode_start(stream, buf, mem, len);
> + ret = uvc_video_decode_start(stream, buf, meta_buf, mem,
> + len);
> if (ret == -EAGAIN)
> uvc_video_next_buffers(stream, &buf, &meta_buf);
> } while (ret == -EAGAIN);
>
next prev parent reply other threads:[~2026-05-11 13:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 5:19 [PATCH v2 0/2] media: uvcvideo: Avoid partial metadata buffers Ricardo Ribalda
2026-04-17 5:19 ` [PATCH v2 1/2] media: uvcvideo: Do not open code uvc_queue_get_current_buffer Ricardo Ribalda
2026-05-11 13:28 ` Hans de Goede
2026-04-17 5:19 ` [PATCH v2 2/2] media: uvcvideo: Avoid partial metadata buffers Ricardo Ribalda
2026-05-11 13:29 ` Hans de Goede [this message]
2026-05-11 14:16 ` [PATCH v2 0/2] " Hans de Goede
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=9ac8787a-b7ba-4f84-a17c-4c1440cabdac@kernel.org \
--to=hansg@kernel.org \
--cc=guennadi.liakhovetski@intel.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@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