diff mbox series

[v6,3/4] media: uvcvideo: Avoid race condition during unregister

Message ID 20240614-guenter-mini-v6-3-7b7fdc3b21b3@chromium.org
State Superseded
Headers show
Series uvcvideo: Attempt N to land UVC race conditions fixes | expand

Commit Message

Ricardo Ribalda June 14, 2024, 12:41 p.m. UTC
The control events are handled asynchronously by the driver. Once the
control event are handled, the urb is re-submitted.

If we simply kill the urb, there is a chance that a control event is
waiting to be processed, which will re-submit the urb after the device is
disconnected.

uvc_status_suspend() flushes the async controls and stops the urb in a
correct manner.

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/usb/uvc/uvc_status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Sept. 25, 2024, 7:20 p.m. UTC | #1
Hi Ricardo,

Thank you for the patch.

I'd write "during status unregister" in the subject line.

On Fri, Jun 14, 2024 at 12:41:29PM +0000, Ricardo Ribalda wrote:
> The control events are handled asynchronously by the driver. Once the
> control event are handled, the urb is re-submitted.
> 
> If we simply kill the urb, there is a chance that a control event is
> waiting to be processed, which will re-submit the urb after the device is
> disconnected.
> 
> uvc_status_suspend() flushes the async controls and stops the urb in a
> correct manner.

"Fix this by calling uvc_status_suspend(), which flushes the async
controls and kills the URB in a race-free manner."

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

> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/usb/uvc/uvc_status.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
> index 375a95dd3011..8fd8250110e2 100644
> --- a/drivers/media/usb/uvc/uvc_status.c
> +++ b/drivers/media/usb/uvc/uvc_status.c
> @@ -294,7 +294,7 @@ int uvc_status_init(struct uvc_device *dev)
>  
>  void uvc_status_unregister(struct uvc_device *dev)
>  {
> -	usb_kill_urb(dev->int_urb);
> +	uvc_status_suspend(dev);
>  	uvc_input_unregister(dev);
>  }
>
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
index 375a95dd3011..8fd8250110e2 100644
--- a/drivers/media/usb/uvc/uvc_status.c
+++ b/drivers/media/usb/uvc/uvc_status.c
@@ -294,7 +294,7 @@  int uvc_status_init(struct uvc_device *dev)
 
 void uvc_status_unregister(struct uvc_device *dev)
 {
-	usb_kill_urb(dev->int_urb);
+	uvc_status_suspend(dev);
 	uvc_input_unregister(dev);
 }