@@ -369,9 +369,12 @@ uvc_function_disable(struct usb_function *f)
{
struct uvc_device *uvc = to_uvc(f);
struct v4l2_event v4l2_event;
+ struct uvc_video *video = &uvc->video;
uvcg_info(f, "%s()\n", __func__);
+ uvcg_video_cancel(video, 1);
+
memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_DISCONNECT;
v4l2_event_queue(&uvc->vdev, &v4l2_event);
@@ -348,6 +348,19 @@ int uvcg_video_pump(struct uvc_video *video)
return 0;
}
+int uvcg_video_cancel(struct uvc_video *video, int disconnect)
+{
+ unsigned int i;
+
+ for (i = 0; i < UVC_NUM_REQUESTS; ++i)
+ if (video->req[i])
+ usb_ep_dequeue(video->ep, video->req[i]);
+
+ uvc_video_free_requests(video);
+ uvcg_queue_cancel(&video->queue, disconnect);
+ return 0;
+}
+
/*
* Enable or disable the video stream.
*/
@@ -16,6 +16,8 @@ struct uvc_video;
int uvcg_video_pump(struct uvc_video *video);
+int uvcg_video_cancel(struct uvc_video *video, int disconnect);
+
int uvcg_video_enable(struct uvc_video *video, int enable);
int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc);
If the streamon ioctl is issued while the stream is already on, then the kernel BUGs. This happens at the BUG_ON in uvc_video_alloc_requests within the call stack from the ioctl handler for VIDIOC_STREAMON. This can also be triggered by starting the stream and then physically disconnecting usb. To fix this, do the streamoff procedures on usb disconnect. Since uvcg_video_enable is not interrupt-safe, add an interrupt-safe version uvcg_video_cancel, and use that. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> v2 Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- Changes in v3: - added interrupt-safe uvcg_video_cancel and used instead of the non-interrupt-save uvcg_video_enable 0 Changes in v2: Nothing drivers/usb/gadget/function/f_uvc.c | 3 +++ drivers/usb/gadget/function/uvc_video.c | 13 +++++++++++++ drivers/usb/gadget/function/uvc_video.h | 2 ++ 3 files changed, 18 insertions(+)