[PATCH v3 2/2] media: uvcvideo: Use wait queue for metadata streamoff
From: Ricardo Ribalda
Date: Tue Nov 24 2026 - 07:06:17 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 844e9baa8066..f44b740cfe55 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -229,11 +229,8 @@ static void uvc_stop_streaming_meta(struct vb2_queue *vq)
spin_lock_irq(&stream->meta.irqlock);
stream->meta.streaming = false;
- 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);
spin_unlock_irq(&stream->meta.irqlock);
uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 5de7f215ee28..fe163edfc0b2 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. */
@@ -2355,6 +2356,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 26d4461f2774..785473928760 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -486,6 +486,7 @@ struct uvc_streaming {
bool in_flight;
bool streaming;
spinlock_t irqlock; /* Protects in_flight and streaming. */
+ wait_queue_head_t wq;
} meta;
/* Context data used by the bulk completion handler. */
--
2.56.1.809.ga0b61035b5-goog