From 70fec1cb10165bfd6b2b45edd40dd146fef850e6 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Tue, 23 Apr 2013 15:50:23 -0700 Subject: [PATCH] CHROMIUM: uvcvideo: Handle status_start while status_stop is in progress. While usb_kill_urb is in progress, calls to usb_submit_urb will fail with -EPERM (documented in Documentation/usb/URB.txt). The UVC driver does not correctly handle this case -- there is no synchronization between uvc_v4l2_open / uvc_status_start and uvc_v4l2_release / uvc_status_stop. This patch adds a retry / timeout when uvc_status_open / usb_submit_urb returns -EPERM. This usually means that usb_kill_urb is in progress, and we just need to wait a while. BUG=chromium:226216 TEST=Manual. Repeat suspend / resume on Stout many times, verify that open() on /dev/video0 never fails. Change-Id: I8a69dab345a18c89e175bd916aa943edd080b6cc Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://gerrit.chromium.org/gerrit/48982 Reviewed-by: Vincent Palatin --- drivers/media/video/uvc/uvc_v4l2.c | 10 +++++++++- drivers/media/video/uvc/uvcvideo.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c index 8db90efca226..ff358cbf6133 100644 --- a/drivers/media/video/uvc/uvc_v4l2.c +++ b/drivers/media/video/uvc/uvc_v4l2.c @@ -476,6 +476,7 @@ static int uvc_v4l2_open(struct file *file) { struct uvc_streaming *stream; struct uvc_fh *handle; + unsigned long timeout; int ret = 0; uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); @@ -496,7 +497,14 @@ static int uvc_v4l2_open(struct file *file) } if (atomic_inc_return(&stream->dev->users) == 1) { - ret = uvc_status_start(stream->dev); + timeout = jiffies + msecs_to_jiffies(UVC_STATUS_START_TIMEOUT); + /* -EPERM means stop in progress, wait for completion */ + do { + ret = uvc_status_start(stream->dev); + if (ret == -EPERM) + usleep_range(5000, 6000); + } while (ret == -EPERM && time_before(jiffies, timeout)); + if (ret < 0) { usb_autopm_put_interface(stream->dev->intf); atomic_dec(&stream->dev->users); diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h index 67f88d85bb16..d2c81d0edc85 100644 --- a/drivers/media/video/uvc/uvcvideo.h +++ b/drivers/media/video/uvc/uvcvideo.h @@ -111,6 +111,7 @@ #define UVC_CTRL_CONTROL_TIMEOUT 300 #define UVC_CTRL_STREAMING_TIMEOUT 5000 +#define UVC_STATUS_START_TIMEOUT 100 /* Maximum allowed number of control mappings per device */ #define UVC_MAX_CONTROL_MAPPINGS 1024 -- 2.20.1