Skip to contentSkip to conversation

media: uvcvideo: Return queued buffers on start_streaming() failure

PATCH In review Michal Pecio 3 participants 3 messages Oct 15, 2025 – Nov 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: uvcvideo: Return queued buffers on start_streaming() failure

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")
---
 drivers/media/usb/uvc/uvc_queue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_queue.c +2 -1
index 790184c9843d..f49c538618bc 100644
@@ -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;
Signature · 1 line
2.48.1
Reviewed-by Ricardo Ribalda on v1 1/1
#1 lore raw

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 :)

Quoted 10 lines · Michal Pecio

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.

Quoted 7 lines

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")
Quoted 26 lines
---
 drivers/media/usb/uvc/uvc_queue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_queue.c +2 -2
index 790184c9843d..f49c538618bc 100644
@@ -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;
--
Quoted 2 lines

2.48.1

--
Ricardo Ribalda

maintainer Reviewed-by
#2 lore raw
Quoted 48 lines · Ricardo Ribalda Delgado

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 :)

Quoted 10 lines · Michal Pecio

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.

Quoted 7 lines

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")
Quoted 17 lines
---
 drivers/media/usb/uvc/uvc_queue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_queue.c +1 -1
index 790184c9843d..f49c538618bc 100644
@@ -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;
 
Quoted 8 lines

drivers/media/usb/uvc/uvc_queue.c static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count) · line 193

Quoted 8 lines
drivers/media/usb/uvc/uvc_queue.c +1 -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.

Signature · 3 lines
Regards,

Laurent Pinchart