[PATCH v3 0/2] media: uvcvideo: Fix race condition on metadata buffers
From: Ricardo Ribalda
Date: Tue Nov 24 2026 - 07:06:34 EST
This series fixes a race condition when calling streamoff only on the
metadata queue while streaming.
The first patch fixes the race condition and the second patch replaces a
busy wait with a waitqueue. It is probably overkilled and this is why it
is a follow-up patch.
Feel free to apply the first patch, both, or squash them into one patch.
Regards!!
Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
---
Changes in v3:
- Fix race condition in uvc_video_get_current_meta_buffer() by checking
stream->meta.streaming under stream->meta.irqlock before peeking the
metadata queue.
- Introduce stream->meta.streaming set in uvc_start_streaming_meta() and
cleared in uvc_stop_streaming_meta() to prevent URB completions from
acquiring metadata buffers or starving stop_streaming.
- Add Reported-by: Georg Neis <neis@xxxxxxxxxx>, who also reported the
same bug internally and pointed at the race condition without
meta.streaming.
- Link to v2: https://lore.kernel.org/r/20260629-uvc-racemeta-v2-0-10e91d2afba0@xxxxxxxxxxxx
Changes in v2:
- Use a new flag in_flight to avoid keeping the spinlock for long
periods of time
- Link to v1: https://lore.kernel.org/r/20250714-uvc-racemeta-v1-1-360de2e15a9a@xxxxxxxxxxxx
---
Ricardo Ribalda (2):
media: uvcvideo: Fix race condition for meta buffer list
media: uvcvideo: Use wait queue for metadata streamoff
drivers/media/usb/uvc/uvc_queue.c | 27 ++++++++++++++++++++++++---
drivers/media/usb/uvc/uvc_video.c | 32 +++++++++++++++++++++++++++++++-
drivers/media/usb/uvc/uvcvideo.h | 4 ++++
3 files changed, 59 insertions(+), 4 deletions(-)
---
base-commit: b7ac871daee981f1963f632586ff9b9d898ce5dd
change-id: 20250714-uvc-racemeta-fee2e69bbfcd
Best regards,
--
Ricardo Ribalda <ribalda@xxxxxxxxxxxx>