diff --git a/usbutils.c b/usbutils.c index 1c811b18..c6f5aeb0 100644 --- a/usbutils.c +++ b/usbutils.c @@ -305,7 +305,7 @@ static struct usb_find_devices find_dev[] = { .epcount = 0, .eps = NULL }, #endif - { DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL } + { DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, NULL } }; #ifdef USE_BFLSC @@ -1647,6 +1647,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u && epdesc->wMaxPacketSize >= found->eps[k].size && epdesc->bEndpointAddress == found->eps[k].ep) { found->eps[k].found = true; + found->wMaxPacketSize = epdesc->wMaxPacketSize; break; } } @@ -2183,6 +2184,11 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, { int err, tries = 0; + /* Limit length of transfer to the largest this descriptor supports + * and leave the higher level functions to transfer more if needed. */ + if (length > cgpu->usbdev->found->wMaxPacketSize) + length = cgpu->usbdev->found->wMaxPacketSize; + cg_rlock(&cgusb_fd_lock); err = libusb_bulk_transfer(dev_handle, endpoint, data, length, transferred, timeout); diff --git a/usbutils.h b/usbutils.h index 03288d2a..b84ee912 100644 --- a/usbutils.h +++ b/usbutils.h @@ -142,6 +142,7 @@ struct usb_find_devices { int config; int interface; unsigned int timeout; + uint16_t wMaxPacketSize; uint16_t latency; int epcount; struct usb_endpoints *eps;