From patchwork Wed Feb 11 05:03:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Rorvick X-Patchwork-Id: 5810311 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0FB8EBF440 for ; Wed, 11 Feb 2015 05:05:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 45AB52021B for ; Wed, 11 Feb 2015 05:05:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1575B20218 for ; Wed, 11 Feb 2015 05:05:57 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 42FF2261AD0; Wed, 11 Feb 2015 06:05:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 84958261687; Wed, 11 Feb 2015 06:03:54 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 921E126167D; Wed, 11 Feb 2015 06:03:53 +0100 (CET) Received: from mail-ig0-f181.google.com (mail-ig0-f181.google.com [209.85.213.181]) by alsa0.perex.cz (Postfix) with ESMTP id BF61F26057C for ; Wed, 11 Feb 2015 06:03:40 +0100 (CET) Received: by mail-ig0-f181.google.com with SMTP id hn18so2256346igb.2 for ; Tue, 10 Feb 2015 21:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=C+ocmxFv2OwxCtnUXS4NJ8VSrBxdv90uFRnuLxuYW5M=; b=UekNPsoSJxijLPSrMdYonUyx2rj5fDiGm71bgYQjQPV5YO1Rzrs6N4D1RwEuQXl2q5 XRZBqP7/RpypUdlj1p9B+9fwE3puCTerkcSvxSc+Cmc5XUbTmeC2i7eoc5RYgem1pX2C 2X+ajPOiRjnHOREZuel4tRJcmQgOA0XsurjzRHy0CdMwh/fqiHD+aGl0d5AF2HVXsbEg 6sogGIqkvRZdlYUBs2rVqdCAv5Nv6+5vvKjDP0MIzC9+yGSoyqwOmZDqlSJtSb3JNcag HCQLGGM5Z1LpTT0qMNxRBK0wrJH0o0R/oP/Kg1gpXqSI5WYXTcuS0boqX9ZBvKUysqmL SsgQ== X-Received: by 10.42.83.147 with SMTP id h19mr1149120icl.95.1423631020043; Tue, 10 Feb 2015 21:03:40 -0800 (PST) Received: from localhost.localdomain.com ([99.135.164.179]) by mx.google.com with ESMTPSA id qd2sm9291297igc.22.2015.02.10.21.03.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Feb 2015 21:03:39 -0800 (PST) From: Chris Rorvick To: Takashi Iwai Date: Tue, 10 Feb 2015 23:03:14 -0600 Message-Id: <1423630997-25464-4-git-send-email-chris@rorvick.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1423630997-25464-1-git-send-email-chris@rorvick.com> References: <1423630997-25464-1-git-send-email-chris@rorvick.com> Cc: Stefan Hajnoczi , alsa-devel@alsa-project.org, Chris Rorvick , linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH 3/6] ALSA: line6: Return error if device not responding X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Put an upper bound on how long we will wait for the device to respond to a read/write request (i.e., 100 milliseconds) and return an error if this is reached. Signed-off-by: Chris Rorvick --- sound/usb/line6/driver.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index 222c14f..2a33f3e 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -297,6 +297,7 @@ static void line6_data_received(struct urb *urb) } #define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */ +#define LINE6_READ_WRITE_MAX_RETRIES 50 /* Read data from device. @@ -307,6 +308,7 @@ int line6_read_data(struct usb_line6 *line6, u16 address, void *data, struct usb_device *usbdev = line6->usbdev; int ret; unsigned char len; + unsigned count; /* query the serial number: */ ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, @@ -320,7 +322,7 @@ int line6_read_data(struct usb_line6 *line6, u16 address, void *data, } /* Wait for data length. We'll get 0xff until length arrives. */ - do { + for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, @@ -333,9 +335,16 @@ int line6_read_data(struct usb_line6 *line6, u16 address, void *data, "receive length failed (error %d)\n", ret); return ret; } - } while (len == 0xff); - if (len != datalen) { + if (len != 0xff) + break; + } + + if (len == 0xff) { + dev_err(line6->ifcdev, "read failed after %d retries\n", + count); + return -EIO; + } else if (len != datalen) { /* should be equal or something went wrong */ dev_err(line6->ifcdev, "length mismatch (expected %d, got %d)\n", @@ -367,6 +376,7 @@ int line6_write_data(struct usb_line6 *line6, u16 address, void *data, struct usb_device *usbdev = line6->usbdev; int ret; unsigned char status; + int count; ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, @@ -379,7 +389,7 @@ int line6_write_data(struct usb_line6 *line6, u16 address, void *data, return ret; } - do { + for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), @@ -394,9 +404,16 @@ int line6_write_data(struct usb_line6 *line6, u16 address, void *data, "receiving status failed (error %d)\n", ret); return ret; } - } while (status == 0xff); - if (status != 0) { + if (status != 0xff) + break; + } + + if (status == 0xff) { + dev_err(line6->ifcdev, "write failed after %d retries\n", + count); + return -EIO; + } else if (status != 0) { dev_err(line6->ifcdev, "write failed (error %d)\n", ret); return -EINVAL; }