Commit 87f0213112a3c69e2c55160b9c674b9de2cde996

Con Kolivas 2014-01-11T16:22:30

Check for loss of device in usb read before any other code on the usbdev

diff --git a/usbutils.c b/usbutils.c
index a56fcf9..4e76e13 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2617,13 +2617,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 		endlen = strlen(end);
 
 	DEVRLOCK(cgpu, pstate);
-	usbdev = cgpu->usbdev;
-	/* Interrupt transfers are guaranteed to be of an expected size (we hope) */
-	if (usbdev->found->intinfos[intinfo].epinfos[epinfo].att == LIBUSB_TRANSFER_TYPE_INTERRUPT)
-		usbbufread = bufsiz;
-	else
-		usbbufread = 512;
-
 	if (cgpu->usbinfo.nodev) {
 		*processed = 0;
 		USB_REJECT(cgpu, MODE_BULK_READ);
@@ -2632,6 +2625,13 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 		goto out_noerrmsg;
 	}
 
+	usbdev = cgpu->usbdev;
+	/* Interrupt transfers are guaranteed to be of an expected size (we hope) */
+	if (usbdev->found->intinfos[intinfo].epinfos[epinfo].att == LIBUSB_TRANSFER_TYPE_INTERRUPT)
+		usbbufread = bufsiz;
+	else
+		usbbufread = 512;
+
 	ftdi = (usbdev->usb_type == USB_TYPE_FTDI);
 
 	USBDEBUG("USB debug: _usb_read(%s (nodev=%s),intinfo=%d,epinfo=%d,buf=%p,bufsiz=%d,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), intinfo, epinfo, buf, (int)bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce));