[PATCH v2 2/2] media: uvcvideo: Use wait queue for metadata streamoff
From: Ricardo Ribalda
Date: Mon Jun 29 2026 - 13:32:39 EST
We are now using a schedule()/loop to wait for in-flight buffers. This
works, but it is not beautiful. Instead we can use wait queues.
Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
---
drivers/media/usb/uvc/uvc_queue.c | 7 ++-----
drivers/media/usb/uvc/uvc_video.c | 2 ++
drivers/media/usb/uvc/uvcvideo.h | 1 +
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index af9dbfcf6f53..266a75862f0a 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -214,11 +214,8 @@ static void uvc_stop_streaming_meta(struct vb2_queue *vq)
lockdep_assert_irqs_enabled();
spin_lock_irq(&stream->meta.irqlock);
- while (stream->meta.in_flight) {
- spin_unlock_irq(&stream->meta.irqlock);
- schedule();
- spin_lock_irq(&stream->meta.irqlock);
- }
+ wait_event_lock_irq(stream->meta.wq, !stream->meta.in_flight,
+ stream->meta.irqlock);
stream->meta.in_flight = true;
spin_unlock_irq(&stream->meta.irqlock);
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index f6b55b3a3308..735080d40862 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1802,6 +1802,7 @@ static void uvc_video_complete(struct urb *urb)
scoped_guard(spinlock_irqsave, &stream->meta.irqlock) {
stream->meta.in_flight = false;
}
+ wake_up(&stream->meta.wq);
}
/* If no async work is needed, resubmit the URB immediately. */
@@ -2357,6 +2358,7 @@ int uvc_video_init(struct uvc_streaming *stream)
INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work);
spin_lock_init(&stream->meta.irqlock);
+ init_waitqueue_head(&stream->meta.wq);
return 0;
}
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 6f1a3381d392..b28f418c6543 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -486,6 +486,7 @@ struct uvc_streaming {
u32 buffersize;
bool in_flight;
spinlock_t irqlock; /* Protects in_flight. */
+ wait_queue_head_t wq;
} meta;
/* Context data used by the bulk completion handler. */
--
2.55.0.rc0.799.gd6f94ed593-goog