Re: [PATCH v2 0/3] usb: gadget: uvc: fix racing between uvc_function_set_alt and streamon/off

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Paul,

On Tuesday, 24 April 2018 23:59:33 EEST Paul Elder wrote:
> Down the call stack from the ioctl handler for VIDIOC_STREAMON,
> uvc_video_alloc_requests contains a BUG_ON, which in the high level,
> triggers when VIDIOC_STREAMON ioctl is issued without VIDIOC_STREAMOFF
> being issued previously.
> 
> This can happen in a few ways, such as if the userspace uvc gadget
> application simply doesn't issue VIDIOC_STREAMOFF. Another way is if
> uvc_function_set_alt with alt 0 is called after it is called with 1 but
> before VIDIOC_STREAMON is called; in this case, UVC_EVENT_STREAMOFF will
> not be queued to userspace, and therefore userspace will never call
> VIDIOC_STREAMOFF.
> 
> To fix this, add two more uvc states: starting and stopping. The
> starting state is entered when uvc_function_set_alt 1 is called, and is
> exited in uvc_v4l2_streamon, when the state is changed to streaming. The
> stopping state is entered when uvc_function_set_alt 0 is called, and is
> exited in uvc_v4l2_streamoff, when the state is changed to connected.

It would be useful to capture this in kerneldoc as a documentation of the 
states enum. I believe writing the description of state transitions down will 
also help you understand the potential race conditions.

> The status phase of the SET_INTERFACE request doesn't need to be delayed
> by the uvc gadget driver, so that is removed.
> 
> Finally, there is another way to trigger the aforementioned BUG: start
> streaming and (physically) disconnect usb. To fix this, call
> uvcg_video_enable 0 in uvc_function_disable.
> 
> Changes in v2:
> 	1. Remove delay usb status phase
> 
> Paul Elder (3):
>   usb: gadget: uvc: synchronize streamon/off with uvc_function_set_alt
>   usb: gadget: uvc: remove delay usb status phase from uvc
>   usb: gadget: uvc: disable stream when disconnected
> 
>  drivers/usb/gadget/function/f_uvc.c    | 14 +++++++++++---
>  drivers/usb/gadget/function/uvc.h      |  2 ++
>  drivers/usb/gadget/function/uvc_v4l2.c | 21 +++++++++++++++------
>  3 files changed, 28 insertions(+), 9 deletions(-)

-- 
Regards,

Laurent Pinchart



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux