Check for no usb device in usb_ftdi_cts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/usbutils.c b/usbutils.c
index 3a945a7..a0d6ba5 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2027,8 +2027,13 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
unsigned char usbbuf[USB_MAX_READ+4], *ptr;
size_t usbbufread;
- if (unlikely(!usbdev))
+ if (cgpu->usbinfo.nodev) {
+ *buf = '\0';
+ *processed = 0;
+ USB_REJECT(cgpu, MODE_BULK_READ);
+
return LIBUSB_ERROR_NO_DEVICE;
+ }
ftdi = (usbdev->usb_type == USB_TYPE_FTDI);
@@ -2037,14 +2042,6 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
if (bufsiz > USB_MAX_READ)
quit(1, "%s USB read request %d too large (max=%d)", cgpu->drv->name, bufsiz, USB_MAX_READ);
- if (cgpu->usbinfo.nodev) {
- *buf = '\0';
- *processed = 0;
- USB_REJECT(cgpu, MODE_BULK_READ);
-
- return LIBUSB_ERROR_NO_DEVICE;
- }
-
if (timeout == DEVTIMEOUT)
timeout = usbdev->found->timeout;
@@ -2204,6 +2201,11 @@ int usb_ftdi_cts(struct cgpu_info *cgpu)
struct cg_usb_device *usbdev = cgpu->usbdev;
unsigned char buf[2], ret;
+ /* We return true in case drivers are waiting indefinitely to try and
+ * write to something that's not there. */
+ if (cgpu->usbinfo.nodev)
+ return true;
+
libusb_control_transfer(usbdev->handle, (uint8_t)FTDI_TYPE_IN,
(uint8_t)5, (uint16_t)0, (uint16_t)0, buf, 2,
DEVTIMEOUT);