Commit f3dfd1be authored by Chris Rorvick's avatar Chris Rorvick Committed by Takashi Iwai

ALSA: line6: Return error if device not responding

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: default avatarChris Rorvick <chris@rorvick.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent e64e94df
...@@ -297,6 +297,7 @@ static void line6_data_received(struct urb *urb) ...@@ -297,6 +297,7 @@ static void line6_data_received(struct urb *urb)
} }
#define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */ #define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */
#define LINE6_READ_WRITE_MAX_RETRIES 50
/* /*
Read data from device. Read data from device.
...@@ -307,6 +308,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data, ...@@ -307,6 +308,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
struct usb_device *usbdev = line6->usbdev; struct usb_device *usbdev = line6->usbdev;
int ret; int ret;
unsigned char len; unsigned char len;
unsigned count;
/* query the serial number: */ /* query the serial number: */
ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
...@@ -320,7 +322,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data, ...@@ -320,7 +322,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
} }
/* Wait for data length. We'll get 0xff until length arrives. */ /* 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); mdelay(LINE6_READ_WRITE_STATUS_DELAY);
ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
...@@ -333,9 +335,16 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data, ...@@ -333,9 +335,16 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
"receive length failed (error %d)\n", ret); "receive length failed (error %d)\n", ret);
return 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 */ /* should be equal or something went wrong */
dev_err(line6->ifcdev, dev_err(line6->ifcdev,
"length mismatch (expected %d, got %d)\n", "length mismatch (expected %d, got %d)\n",
...@@ -367,6 +376,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data, ...@@ -367,6 +376,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
struct usb_device *usbdev = line6->usbdev; struct usb_device *usbdev = line6->usbdev;
int ret; int ret;
unsigned char status; unsigned char status;
int count;
ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
...@@ -379,7 +389,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data, ...@@ -379,7 +389,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
return ret; return ret;
} }
do { for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
mdelay(LINE6_READ_WRITE_STATUS_DELAY); mdelay(LINE6_READ_WRITE_STATUS_DELAY);
ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
...@@ -394,9 +404,16 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data, ...@@ -394,9 +404,16 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
"receiving status failed (error %d)\n", ret); "receiving status failed (error %d)\n", ret);
return 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); dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment