[PATCH 3/4] usb: gadget: uvc: synchronize usb status phase delay for uvc_function_set_alt

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

 



This patch depends on the previous patch in this series:
[PATCH 2/4] usb: gadget: composite: add function to increment
delayed_status

The completion of the usb status phase from uvc_function_set_alt needs
to be delayed until uvc_v4l2_streamon/off. This is currently done by
uvc_function_set_alt returning USB_GADGET_DELAYED_STATUS and
composite_setup detecting this to increment cdev->delayed_status.
However, if uvc_v4l2_streamon/off is called in between this return and
increment, uvc_function_setup_continue within uvc_v4l2_streamon/off will
WARN that cdev->delayed_status is zero.

To fix this, use usb_composite_setup_delay to increment
cdev->delayed_status, and then return 0 so that composite_setup doesn't
increment cdev->delayed_status again.

Signed-off-by: Paul Elder <paul.elder@xxxxxxxx>
---
 drivers/usb/gadget/function/f_uvc.c    | 13 ++++++++++++-
 drivers/usb/gadget/function/uvc_v4l2.c |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 9b63b28a1ee3..3324d36e809c 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -334,6 +334,8 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
 
 		uvc->state = UVC_STATE_STOPPING;
 
+		usb_composite_setup_delay(cdev);
+
 		memset(&v4l2_event, 0, sizeof(v4l2_event));
 		v4l2_event.type = UVC_EVENT_STREAMOFF;
 		v4l2_event_queue(&uvc->vdev, &v4l2_event);
@@ -358,10 +360,19 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
 
 		uvc->state = UVC_STATE_STARTING;
 
+		usb_composite_setup_delay(cdev);
+
 		memset(&v4l2_event, 0, sizeof(v4l2_event));
 		v4l2_event.type = UVC_EVENT_STREAMON;
 		v4l2_event_queue(&uvc->vdev, &v4l2_event);
-		return USB_GADGET_DELAYED_STATUS;
+
+		/*
+		 * Normally we would return USB_GADGET_DELAYED_STATUS
+		 * but status phase might try to continue in between
+		 * this function returning and the delayed status
+		 * actually being set
+		 */
+		return 0;
 
 	default:
 		return -EINVAL;
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index fdf02b6987c0..0592e13d861c 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -235,6 +235,8 @@ uvc_v4l2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
 
 	uvc->state = UVC_STATE_CONNECTED;
 
+	uvc_function_setup_continue(uvc);
+
 	return 0;
 
 }
-- 
2.17.0

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