[PATCH v3 2/2] media: go7007: return pending buffers on stop_streaming()

From: YuanZhe Liu

Date: Wed Nov 25 2026 - 04:18:29 EST


The vb2 framework hands buffers to the driver through buf_queue() and
expects stop_streaming() to give the buffers that are still owned by the
driver back with VB2_BUF_STATE_DONE or VB2_BUF_STATE_ERROR.

go7007_stop_streaming() instead just re-initializes go->vidq_active,
dropping any pending buffers without returning them to vb2. That leaves
owned_by_drv_count elevated and makes __vb2_queue_cancel() report a
driver bug when the queue is cancelled.

Return every pending buffer with VB2_BUF_STATE_ERROR and clear
go->active_buf, which may still point into the list.

Fixes: 7955f03d18d1 ("[media] go7007: move out of staging into drivers/media/usb.")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/media/usb/go7007/go7007-v4l2.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index 0b32cb58142b..6ab067d56b7c 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -440,6 +440,7 @@ static int go7007_start_streaming(struct vb2_queue *q, unsigned int count)
static void go7007_stop_streaming(struct vb2_queue *q)
{
struct go7007 *go = vb2_get_drv_priv(q);
+ struct go7007_buffer *vb, *tmp;
unsigned long flags;

go7007_stream_stop(go);
@@ -449,7 +450,11 @@ static void go7007_stop_streaming(struct vb2_queue *q)
call_all(&go->v4l2_dev, video, s_stream, 0);

spin_lock_irqsave(&go->spinlock, flags);
- INIT_LIST_HEAD(&go->vidq_active);
+ list_for_each_entry_safe(vb, tmp, &go->vidq_active, list) {
+ list_del(&vb->list);
+ vb2_buffer_done(&vb->vb.vb2_buf, VB2_BUF_STATE_ERROR);
+ }
+ go->active_buf = NULL;
spin_unlock_irqrestore(&go->spinlock, flags);
v4l2_ctrl_grab(go->mpeg_video_gop_size, false);
v4l2_ctrl_grab(go->mpeg_video_gop_closure, false);
--
2.34.1