Limit USB transfers to the max size reported by the descriptors.
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
diff --git a/usbutils.c b/usbutils.c
index 1c811b1..c6f5aeb 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 03288d2..b84ee91 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;