From patchwork Thu Mar 8 17:21:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 10268557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9273F602BD for ; Thu, 8 Mar 2018 17:22:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7021F298A1 for ; Thu, 8 Mar 2018 17:22:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EE7829972; Thu, 8 Mar 2018 17:22:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A8A298A1 for ; Thu, 8 Mar 2018 17:21:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935960AbeCHRVk (ORCPT ); Thu, 8 Mar 2018 12:21:40 -0500 Received: from mout.gmx.net ([212.227.15.19]:40789 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934104AbeCHRVj (ORCPT ); Thu, 8 Mar 2018 12:21:39 -0500 Received: from axis700.grange ([84.44.204.122]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MK17F-1euoZq1dED-001RCG; Thu, 08 Mar 2018 18:21:23 +0100 Received: by axis700.grange (Postfix, from userid 1000) id 79A0A60EFB; Thu, 8 Mar 2018 18:21:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 63EAE60AE4; Thu, 8 Mar 2018 18:21:22 +0100 (CET) Date: Thu, 8 Mar 2018 18:21:21 +0100 (CET) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List cc: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil Subject: [PATCH RESEND 2/2 v6] uvcvideo: handle control pipe protocol STALLs Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Provags-ID: V03:K0:cmiQ21YYurzWhBN9ddhp/gOW2Oni95Y+EjiDtfB1KWZhsGpIidw eclCJHYGR5Z/e4eWTU57wE6WlfNl2Q+4UM86ao/E0befpK4WRajoO157UprKuz63/v9vdWh AvZyY0w2v/sAH5ZM2RCBaEhZ0swHrGukUEudQTvHL1+tDni5YtkXaO9ENrQUTd1lIoKk5YI c590hN9/b07dwzw/uwx8Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:f4XZevVihTw=:X61wz1Vb7zUa5wCSHY667a Bo6q1uLKN+hbRuAmczdELwDb/rFci2zFUHBZ4Qk+RO0oK3CA096Tgp4qElTXD6W58RiYDoM8r aWAPl63InCDDWklpGqJ+2/6ylce/nWZfSzjWjbZvv5IaYf2UJmVxkm1+LtekOcWCFQa6AF8oq hix4aKc4U0kI5Akgl62faEowTERrL8Mp7G6QuXBEIyms9I8NVDemhY13TsR9UO25F5LEHXKBq HD2Q/XcfnyOFe1SI4DyLUGblgCIc7zmuCZ5mj9MKhvrZV+6TMAXNzt4B0ZIZOotakYzPsgImE er0fTvMJjUkdWGm8prfq4xq/0QvUsQ7fVyW6hhu4XDSRfxQ/dQSJuxyha+lL94CeCqAF/9Tm1 tAS9xqjdy1RyVpv/Bq9ZCdUTvID0mSf9ZZ+7Wn3l1m464FN+IoyRsBoXqfIwv594i0vXGcAks SN46gOl+3WXR0cI2eGn3TFuNql/anDJrm1S7RMJLAtMQGtK/ewtWy37W06tQqN37Jo2S44Yk4 mJ0RHMqk0cOy1tGfihIFmLZ7YlOJEqj47DmTyzgbqayY5UN/DYQi5x/4hojF0r85wWnK/OBVo TVQcdGEG5M8koRhU6R67ddbI9e9vDcbJsEUD0uMvzVzItc70MEW1XQCkiX6hpoDADjjpetuRY xIfS6RJeNQ5V7hxN656+6PtqrZu+U+1WzxrB55uM1aQgQryQ4+7vOJaKiPqeE83aOBxMEtHmQ nlHUdsEQtX/D7OpMvDNgTybdTbCyjz+UW7PVZDHIlt4vgpy8dVPrg89glGWTYjYLE4dzmov6D eEh3dpHjpcAudvKzI2VuZxZlbktcXz34eeuli2Y953PpSK9IEI= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a command ends up in a STALL on the control pipe, use the Request Error Code control to provide a more precise error information to the user. Signed-off-by: Guennadi Liakhovetski --- drivers/media/usb/uvc/uvc_video.c | 59 +++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 2fc0bf2..cfcc4861 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -34,15 +34,59 @@ static int __uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, __u8 intfnum, __u8 cs, void *data, __u16 size, int timeout) { - __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE; + __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE, tmp, error; unsigned int pipe; + int ret; pipe = (query & 0x80) ? usb_rcvctrlpipe(dev->udev, 0) : usb_sndctrlpipe(dev->udev, 0); type |= (query & 0x80) ? USB_DIR_IN : USB_DIR_OUT; - return usb_control_msg(dev->udev, pipe, query, type, cs << 8, + ret = usb_control_msg(dev->udev, pipe, query, type, cs << 8, unit << 8 | intfnum, data, size, timeout); + + if (ret != -EPIPE) + return ret; + + tmp = *(u8 *)data; + + pipe = usb_rcvctrlpipe(dev->udev, 0); + type = USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN; + ret = usb_control_msg(dev->udev, pipe, UVC_GET_CUR, type, + UVC_VC_REQUEST_ERROR_CODE_CONTROL << 8, + unit << 8 | intfnum, data, 1, timeout); + error = *(u8 *)data; + *(u8 *)data = tmp; + + if (ret < 0) + return ret; + + if (!ret) + return -EINVAL; + + uvc_trace(UVC_TRACE_CONTROL, "Control error %u\n", error); + + switch (error) { + case 0: + /* Cannot happen - we received a STALL */ + return -EPIPE; + case 1: /* Not ready */ + return -EAGAIN; + case 2: /* Wrong state */ + return -EILSEQ; + case 3: /* Power */ + return -EREMOTE; + case 4: /* Out of range */ + return -ERANGE; + case 5: /* Invalid unit */ + case 6: /* Invalid control */ + case 7: /* Invalid Request */ + case 8: /* Invalid value within range */ + default: /* reserved or unknown */ + break; + } + + return -EINVAL; } static const char *uvc_query_name(__u8 query) @@ -80,7 +124,7 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, uvc_printk(KERN_ERR, "Failed to query (%s) UVC control %u on " "unit %u: %d (exp. %u).\n", uvc_query_name(query), cs, unit, ret, size); - return -EIO; + return ret < 0 ? ret : -EIO; } return 0; @@ -203,13 +247,15 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream, uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non " "compliance - GET_DEF(PROBE) not supported. " "Enabling workaround.\n"); - ret = -EIO; + if (ret >= 0) + ret = -EIO; goto out; } else if (ret != size) { uvc_printk(KERN_ERR, "Failed to query (%u) UVC %s control : " "%d (exp. %u).\n", query, probe ? "probe" : "commit", ret, size); - ret = -EIO; + if (ret >= 0) + ret = -EIO; goto out; } @@ -290,7 +336,8 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream, uvc_printk(KERN_ERR, "Failed to set UVC %s control : " "%d (exp. %u).\n", probe ? "probe" : "commit", ret, size); - ret = -EIO; + if (ret >= 0) + ret = -EIO; } kfree(data);