diff --git a/usbutils.c b/usbutils.c index 3a945a7c..a0d6ba5b 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);