[PATCH v2] media: msi2500: remove !dev->udev check in msi2500_buf_queue()
From: zhangdaolong
Date: Wed Nov 11 2026 - 21:10:53 EST
When vb2_start_streaming() is invoked, it first passes all pre-queued
buffers on q->queued_list to the driver via buf_queue() before setting
q->start_streaming_called and invoking start_streaming(). If
start_streaming() subsequently returns an error, videobuf2 requires all
buffers passed to the driver to be returned with VB2_BUF_STATE_QUEUED
and warns via WARN_ON(!list_empty(&q->done_list)) if any buffer was
completed with VB2_BUF_STATE_ERROR or VB2_BUF_STATE_DONE.
If the USB device disconnects before vb2_start_streaming() runs (for
example when v4l2_read() races with msi2500_disconnect()), dev->udev is
already NULL when vb2_start_streaming() enters. msi2500_buf_queue() sees
!dev->udev and immediately completes each pre-queued buffer with
VB2_BUF_STATE_ERROR (moving it onto q->done_list) instead of adding it
to dev->queued_bufs. Right after that, msi2500_start_streaming() also
sees !dev->udev and returns -ENODEV, triggering
WARN_ON(!list_empty(&q->done_list)) in vb2_start_streaming().
The !dev->udev check in msi2500_buf_queue() is unnecessary: ioctls check
video_is_registered() under vb_queue_lock while msi2500_disconnect()
clears dev->udev and unregisters the video device under the same lock,
and if v4l2_read() races with disconnect before acquiring vb_queue_lock,
msi2500_start_streaming() immediately catches !dev->udev and returns all
buffers on dev->queued_bufs with VB2_BUF_STATE_QUEUED. Remove the check
from msi2500_buf_queue().
Reported-by: syzbot+930e6201080a31e9d0c8@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=930e6201080a31e9d0c8
Fixes: 977e444f59ad ("[media] Mirics MSi3101 SDR Dongle driver")
Cc: stable@xxxxxxxxxxxxxxx
Suggested-by: Hans Verkuil <hverkuil+cisco@xxxxxxxxxx>
Signed-off-by: zhangdaolong <dlzhangak@xxxxxxxxxxxxxx>
---
v2:
- Remove the !dev->udev check in msi2500_buf_queue() completely instead
of checking vb2_start_streaming_called() (Hans Verkuil).
drivers/media/usb/msi2500/msi2500.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index 282256ab812a..3382bb62541f 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -623,12 +623,6 @@ static void msi2500_buf_queue(struct vb2_buffer *vb)
vb);
unsigned long flags;
- /* Check the device has not disconnected between prep and queuing */
- if (unlikely(!dev->udev)) {
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
- return;
- }
-
spin_lock_irqsave(&dev->queued_bufs_lock, flags);
list_add_tail(&buf->list, &dev->queued_bufs);
spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
--
2.48.1