mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] media: go7007: return queued buffers on start_streaming() failure
@ 2026-11-12 14:05 YuanZhe Liu
  2026-11-25  8:52 ` Hans Verkuil
  0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-11-12 14:05 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, stable, Bin Yu, Cheng Wen

The vb2 framework hands ownership of every queued buffer to the driver
through the buf_queue() callback before start_streaming() is called.  If
start_streaming() then returns an error, the driver must return those
buffers to vb2 with vb2_buffer_done() and VB2_BUF_STATE_QUEUED.
Otherwise vb2_start_streaming() fires WARN_ON(owned_by_drv_count) and
forcibly reclaims the buffers.

go7007_start_streaming() returns -EIO when go7007_start_encoder() fails,
which happens for example when a USB transfer cannot be submitted because
the device has been disconnected:

    go7007 1-1:1.0: error submitting audio urb 5: -2
    go7007 1-1:1.0: error starting stream transfer
    WARNING: drivers/media/common/videobuf2/videobuf2-core.c:1797 at vb2_start_streaming

but it leaves the already queued buffers on go->vidq_active.  Give them
back to vb2 with VB2_BUF_STATE_QUEUED before bailing out.

Fixes: 7955f03d18d1 ("[media] go7007: move out of staging into drivers/media/usb.")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
Changes in v2:
- Inline the buffer return into go7007_start_streaming() as requested and
  drop the separate helper.
- Drop the redundant go->active_buf = NULL: active_buf is still NULL when
  go7007_start_encoder() fails.

 drivers/media/usb/go7007/go7007-v4l2.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index 2087ffcb85a5..030a127cb9ea 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -409,8 +409,26 @@ static int go7007_start_streaming(struct vb2_queue *q, unsigned int count)
 	else
 		ret = 0;
 	mutex_unlock(&go->hw_lock);
-	if (ret)
+	if (ret) {
+		struct go7007_buffer *vb, *tmp;
+		unsigned long flags;
+		LIST_HEAD(buffers);
+
+		/*
+		 * The queued buffers were handed over to the driver before
+		 * start_streaming() was called, so they have to be returned
+		 * with VB2_BUF_STATE_QUEUED.
+		 */
+		spin_lock_irqsave(&go->spinlock, flags);
+		list_splice_init(&go->vidq_active, &buffers);
+		spin_unlock_irqrestore(&go->spinlock, flags);
+
+		list_for_each_entry_safe(vb, tmp, &buffers, list) {
+			list_del(&vb->list);
+			vb2_buffer_done(&vb->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
+		}
 		return ret;
+	}
 	call_all(&go->v4l2_dev, video, s_stream, 1);
 	v4l2_ctrl_grab(go->mpeg_video_gop_size, true);
 	v4l2_ctrl_grab(go->mpeg_video_gop_closure, true);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] media: go7007: return queued buffers on start_streaming() failure
  2026-11-12 14:05 [PATCH v2] media: go7007: return queued buffers on start_streaming() failure YuanZhe Liu
@ 2026-11-25  8:52 ` Hans Verkuil
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2026-11-25  8:52 UTC (permalink / raw)
  To: YuanZhe Liu, Hans Verkuil, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, stable, Bin Yu, Cheng Wen

On 12/11/2026 15:05, YuanZhe Liu wrote:
> The vb2 framework hands ownership of every queued buffer to the driver
> through the buf_queue() callback before start_streaming() is called.  If
> start_streaming() then returns an error, the driver must return those
> buffers to vb2 with vb2_buffer_done() and VB2_BUF_STATE_QUEUED.
> Otherwise vb2_start_streaming() fires WARN_ON(owned_by_drv_count) and
> forcibly reclaims the buffers.
> 
> go7007_start_streaming() returns -EIO when go7007_start_encoder() fails,
> which happens for example when a USB transfer cannot be submitted because
> the device has been disconnected:
> 
>     go7007 1-1:1.0: error submitting audio urb 5: -2
>     go7007 1-1:1.0: error starting stream transfer
>     WARNING: drivers/media/common/videobuf2/videobuf2-core.c:1797 at vb2_start_streaming
> 
> but it leaves the already queued buffers on go->vidq_active.  Give them
> back to vb2 with VB2_BUF_STATE_QUEUED before bailing out.
> 
> Fixes: 7955f03d18d1 ("[media] go7007: move out of staging into drivers/media/usb.")
> Cc: stable@vger.kernel.org
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
> ---
> Changes in v2:
> - Inline the buffer return into go7007_start_streaming() as requested and
>   drop the separate helper.
> - Drop the redundant go->active_buf = NULL: active_buf is still NULL when
>   go7007_start_encoder() fails.
> 
>  drivers/media/usb/go7007/go7007-v4l2.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
> index 2087ffcb85a5..030a127cb9ea 100644
> --- a/drivers/media/usb/go7007/go7007-v4l2.c
> +++ b/drivers/media/usb/go7007/go7007-v4l2.c
> @@ -409,8 +409,26 @@ static int go7007_start_streaming(struct vb2_queue *q, unsigned int count)
>  	else
>  		ret = 0;
>  	mutex_unlock(&go->hw_lock);
> -	if (ret)
> +	if (ret) {
> +		struct go7007_buffer *vb, *tmp;
> +		unsigned long flags;
> +		LIST_HEAD(buffers);
> +
> +		/*
> +		 * The queued buffers were handed over to the driver before
> +		 * start_streaming() was called, so they have to be returned
> +		 * with VB2_BUF_STATE_QUEUED.
> +		 */
> +		spin_lock_irqsave(&go->spinlock, flags);
> +		list_splice_init(&go->vidq_active, &buffers);
> +		spin_unlock_irqrestore(&go->spinlock, flags);
> +
> +		list_for_each_entry_safe(vb, tmp, &buffers, list) {

Why not just walk go->vidq_active? There is no need for list_splice_init AFAICS.
Keep it simple.

> +			list_del(&vb->list);
> +			vb2_buffer_done(&vb->vb.vb2_buf, VB2_BUF_STATE_QUEUED);

Looking a bit closer, it seems that go7007_stop_streaming() fails to return any
pending buffers to state VB2_BUF_STATE_ERROR. It just re-inits go->vidq_active
instead of properly returning any queued buffers.

Can you fix that as well?

Regards,

	Hans

> +		}
>  		return ret;
> +	}
>  	call_all(&go->v4l2_dev, video, s_stream, 1);
>  	v4l2_ctrl_grab(go->mpeg_video_gop_size, true);
>  	v4l2_ctrl_grab(go->mpeg_video_gop_closure, true);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25  8:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 14:05 [PATCH v2] media: go7007: return queued buffers on start_streaming() failure YuanZhe Liu
2026-11-25  8:52 ` Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®