public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: uvcvideo: Return queued buffers on start_streaming() failure
@ 2025-10-15 11:36 Michal Pecio
  2025-10-21 10:47 ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Pecio @ 2025-10-15 11:36 UTC (permalink / raw)
  To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab
  Cc: Hans Verkuil, Ricardo Ribalda, linux-media, linux-kernel

Return buffers if streaming fails to start due to uvc_pm_get() error.

This bug may be responsible for a warning I got running

    while :; do yavta -c3 /dev/video0; done

on an xHCI controller which failed under this workload.
I had no luck reproducing this warning again to confirm.

xhci_hcd 0000:09:00.0: HC died; cleaning up
usb 13-2: USB disconnect, device number 2
WARNING: CPU: 2 PID: 29386 at drivers/media/common/videobuf2/videobuf2-core.c:1803 vb2_start_streaming+0xac/0x120

Fixes: 7dd56c47784a ("media: uvcvideo: Remove stream->is_streaming field")
Cc: stable@vger.kernel.org
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
---
 drivers/media/usb/uvc/uvc_queue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 790184c9843d..f49c538618bc 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -177,7 +177,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
 
 	ret = uvc_pm_get(stream->dev);
 	if (ret)
-		return ret;
+		goto return_buffers;
 
 	queue->buf_used = 0;
 
@@ -187,6 +187,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
 
 	uvc_pm_put(stream->dev);
 
+return_buffers:
 	uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
 
 	return ret;
-- 
2.48.1

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

* Re: [PATCH] media: uvcvideo: Return queued buffers on start_streaming() failure
  2025-10-15 11:36 [PATCH] media: uvcvideo: Return queued buffers on start_streaming() failure Michal Pecio
@ 2025-10-21 10:47 ` Ricardo Ribalda Delgado
  2025-11-13 21:37   ` Laurent Pinchart
  0 siblings, 1 reply; 3+ messages in thread
From: Ricardo Ribalda Delgado @ 2025-10-21 10:47 UTC (permalink / raw)
  To: Michal Pecio
  Cc: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
	Hans Verkuil, Ricardo Ribalda, linux-media, linux-kernel

Hi Michal

It seems that the device was disconnected while doing streamon. That
caused uvc_pm_get() to fail and exit without returning the buffers.

Your patch is not going to help to fix:
xhci_hcd 0000:09:00.0: HC died; cleaning up
usb 13-2: USB disconnect, device number 2

But it is fixing an issue. thanks :)

On Wed, Oct 15, 2025 at 1:36 PM Michal Pecio <michal.pecio@gmail.com> wrote:
>
> Return buffers if streaming fails to start due to uvc_pm_get() error.
>
> This bug may be responsible for a warning I got running
>
>     while :; do yavta -c3 /dev/video0; done
>
> on an xHCI controller which failed under this workload.
> I had no luck reproducing this warning again to confirm.
>
> xhci_hcd 0000:09:00.0: HC died; cleaning up
> usb 13-2: USB disconnect, device number 2
> WARNING: CPU: 2 PID: 29386 at drivers/media/common/videobuf2/videobuf2-core.c:1803 vb2_start_streaming+0xac/0x120
>
> Fixes: 7dd56c47784a ("media: uvcvideo: Remove stream->is_streaming field")
> Cc: stable@vger.kernel.org
> Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>

> ---
>  drivers/media/usb/uvc/uvc_queue.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> index 790184c9843d..f49c538618bc 100644
> --- a/drivers/media/usb/uvc/uvc_queue.c
> +++ b/drivers/media/usb/uvc/uvc_queue.c
> @@ -177,7 +177,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
>
>         ret = uvc_pm_get(stream->dev);
>         if (ret)
> -               return ret;
> +               goto return_buffers;
>
>         queue->buf_used = 0;
>
> @@ -187,6 +187,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
>
>         uvc_pm_put(stream->dev);
>
> +return_buffers:
>         uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
>
>         return ret;
> --
> 2.48.1
>


--
Ricardo Ribalda

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

* Re: [PATCH] media: uvcvideo: Return queued buffers on start_streaming() failure
  2025-10-21 10:47 ` Ricardo Ribalda Delgado
@ 2025-11-13 21:37   ` Laurent Pinchart
  0 siblings, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2025-11-13 21:37 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Michal Pecio, Hans de Goede, Mauro Carvalho Chehab, Hans Verkuil,
	Ricardo Ribalda, linux-media, linux-kernel

On Tue, Oct 21, 2025 at 12:47:23PM +0200, Ricardo Ribalda Delgado wrote:
> Hi Michal
> 
> It seems that the device was disconnected while doing streamon. That
> caused uvc_pm_get() to fail and exit without returning the buffers.
> 
> Your patch is not going to help to fix:
> xhci_hcd 0000:09:00.0: HC died; cleaning up
> usb 13-2: USB disconnect, device number 2
> 
> But it is fixing an issue. thanks :)
> 
> On Wed, Oct 15, 2025 at 1:36 PM Michal Pecio <michal.pecio@gmail.com> wrote:
> >
> > Return buffers if streaming fails to start due to uvc_pm_get() error.
> >
> > This bug may be responsible for a warning I got running
> >
> >     while :; do yavta -c3 /dev/video0; done
> >
> > on an xHCI controller which failed under this workload.
> > I had no luck reproducing this warning again to confirm.
> >
> > xhci_hcd 0000:09:00.0: HC died; cleaning up
> > usb 13-2: USB disconnect, device number 2
> > WARNING: CPU: 2 PID: 29386 at drivers/media/common/videobuf2/videobuf2-core.c:1803 vb2_start_streaming+0xac/0x120
> >
> > Fixes: 7dd56c47784a ("media: uvcvideo: Remove stream->is_streaming field")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> 
> > ---
> >  drivers/media/usb/uvc/uvc_queue.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> > index 790184c9843d..f49c538618bc 100644
> > --- a/drivers/media/usb/uvc/uvc_queue.c
> > +++ b/drivers/media/usb/uvc/uvc_queue.c
> > @@ -177,7 +177,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
> >
> >         ret = uvc_pm_get(stream->dev);
> >         if (ret)
> > -               return ret;
> > +               goto return_buffers;
> >
> >         queue->buf_used = 0;
> >
> > @@ -187,6 +187,7 @@ static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
> >
> >         uvc_pm_put(stream->dev);
> >
> > +return_buffers:
> >         uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
> >
> >         return ret;

Error labels should start with err_. I'd like to take this as an
opportunity to reorganize the error path with something like

	ret = uvc_pm_get(stream->dev);
	if (ret)
		goto err_buffers;
 
	queue->buf_used = 0;

	ret = uvc_video_start_streaming(stream);
	if (ret)
		goto err_pm;

	return 0;
 
err_pm:
	uvc_pm_put(stream->dev);
err_buffers:
	uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
	return ret;


I'll send a v2 that does this.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2025-11-13 21:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-15 11:36 [PATCH] media: uvcvideo: Return queued buffers on start_streaming() failure Michal Pecio
2025-10-21 10:47 ` Ricardo Ribalda Delgado
2025-11-13 21:37   ` Laurent Pinchart

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