Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: uvc: Move usb_ep_disable() to uvcg_video_enable()
@ 2023-06-15  9:34 Daniel Scally
  2023-06-15 17:15 ` Laurent Pinchart
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Scally @ 2023-06-15  9:34 UTC (permalink / raw)
  To: Laurent Pinchart, Daniel Scally, Greg Kroah-Hartman, linux-usb

Currently the UVC Gadget's .set_alt() callback disables the USB
endpoint, following which a V4L2 event is queued that closes
down the workqueue. This ordering results in repeated calls to
usb_ep_queue() from the workqueue whilst usb_ep_disable() is
running - behaviour that the documentation for usb_ep_disable()
specifically prohibits.

Move the call to usb_ep_disable() until after cancel_work_sync(),
which will guarantee the endpoint is no longer in use when
usb_ep_disable() is called.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
 drivers/usb/gadget/function/f_uvc.c     | 3 ---
 drivers/usb/gadget/function/uvc_video.c | 4 ++++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 5e919fb65833..4b91bd572a83 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -337,9 +337,6 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
 		if (uvc->state != UVC_STATE_STREAMING)
 			return 0;
 
-		if (uvc->video.ep)
-			usb_ep_disable(uvc->video.ep);
-
 		memset(&v4l2_event, 0, sizeof(v4l2_event));
 		v4l2_event.type = UVC_EVENT_STREAMOFF;
 		v4l2_event_queue(&uvc->vdev, &v4l2_event);
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index 91af3b1ef0d4..c7e38fa26492 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -499,6 +499,10 @@ int uvcg_video_enable(struct uvc_video *video, int enable)
 
 	if (!enable) {
 		cancel_work_sync(&video->pump);
+
+		if (video->ep)
+			usb_ep_disable(video->ep);
+
 		uvcg_queue_cancel(&video->queue, 0);
 
 		for (i = 0; i < video->uvc_num_requests; ++i)
-- 
2.34.1


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

end of thread, other threads:[~2023-09-15 23:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-15  9:34 [PATCH] usb: gadget: uvc: Move usb_ep_disable() to uvcg_video_enable() Daniel Scally
2023-06-15 17:15 ` Laurent Pinchart
2023-08-30 20:38   ` Avichal Rakesh
2023-09-04 14:36     ` Michael Grzeschik
2023-09-08 15:54       ` Avichal Rakesh
2023-09-11  0:50         ` Michael Grzeschik
2023-09-12  4:26           ` Avichal Rakesh
2023-09-15 23:13             ` Michael Grzeschik

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