Skip to content

Commit b7ef536

Browse files
ribaldahverkuil
authored andcommitted
media: uvcvideo: Handle locks in uvc_queue_return_buffers
Most of the calls to uvc_queue_return_buffers() wrap the call with spin_lock_irq()/spin_unlock_irq(). Rename uvc_queue_return_buffers to __uvc_queue_return_buffers to indicate that this is the version that does not handle locks and create a new version of the function that handles the lock. Reviewed-by: Hans de Goede <hansg@kernel.org> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Link: https://lore.kernel.org/r/20250616-uvc-fop-v4-2-250286570ee7@chromium.org Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Hans de Goede <hansg@kernel.org> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
1 parent c93d73c commit b7ef536

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

drivers/media/usb/uvc/uvc_queue.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ static inline struct uvc_buffer *uvc_vbuf_to_buffer(struct vb2_v4l2_buffer *buf)
4242
*
4343
* This function must be called with the queue spinlock held.
4444
*/
45-
static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
46-
enum uvc_buffer_state state)
45+
static void __uvc_queue_return_buffers(struct uvc_video_queue *queue,
46+
enum uvc_buffer_state state)
4747
{
4848
enum vb2_buffer_state vb2_state = state == UVC_BUF_STATE_ERROR
4949
? VB2_BUF_STATE_ERROR
5050
: VB2_BUF_STATE_QUEUED;
5151

52+
lockdep_assert_held(&queue->irqlock);
53+
5254
while (!list_empty(&queue->irqqueue)) {
5355
struct uvc_buffer *buf = list_first_entry(&queue->irqqueue,
5456
struct uvc_buffer,
@@ -59,6 +61,14 @@ static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
5961
}
6062
}
6163

64+
static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
65+
enum uvc_buffer_state state)
66+
{
67+
spin_lock_irq(&queue->irqlock);
68+
__uvc_queue_return_buffers(queue, state);
69+
spin_unlock_irq(&queue->irqlock);
70+
}
71+
6272
/* -----------------------------------------------------------------------------
6373
* videobuf2 queue operations
6474
*/
@@ -171,9 +181,7 @@ static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
171181
if (ret == 0)
172182
return 0;
173183

174-
spin_lock_irq(&queue->irqlock);
175184
uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
176-
spin_unlock_irq(&queue->irqlock);
177185

178186
return ret;
179187
}
@@ -187,9 +195,7 @@ static void uvc_stop_streaming(struct vb2_queue *vq)
187195
if (vq->type != V4L2_BUF_TYPE_META_CAPTURE)
188196
uvc_video_stop_streaming(uvc_queue_to_stream(queue));
189197

190-
spin_lock_irq(&queue->irqlock);
191198
uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
192-
spin_unlock_irq(&queue->irqlock);
193199
}
194200

195201
static const struct vb2_ops uvc_queue_qops = {
@@ -263,7 +269,7 @@ void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
263269
unsigned long flags;
264270

265271
spin_lock_irqsave(&queue->irqlock, flags);
266-
uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
272+
__uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
267273
/*
268274
* This must be protected by the irqlock spinlock to avoid race
269275
* conditions between uvc_buffer_queue and the disconnection event that

0 commit comments

Comments
 (0)