Browse Source

Limit USB transfers to the max size reported by the descriptors.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
f4d74116d3
  1. 8
      usbutils.c
  2. 1
      usbutils.h

8
usbutils.c

@ -305,7 +305,7 @@ static struct usb_find_devices find_dev[] = {
.epcount = 0, .epcount = 0,
.eps = NULL }, .eps = NULL },
#endif #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 #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->wMaxPacketSize >= found->eps[k].size
&& epdesc->bEndpointAddress == found->eps[k].ep) { && epdesc->bEndpointAddress == found->eps[k].ep) {
found->eps[k].found = true; found->eps[k].found = true;
found->wMaxPacketSize = epdesc->wMaxPacketSize;
break; break;
} }
} }
@ -2183,6 +2184,11 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
{ {
int err, tries = 0; 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); cg_rlock(&cgusb_fd_lock);
err = libusb_bulk_transfer(dev_handle, endpoint, data, length, err = libusb_bulk_transfer(dev_handle, endpoint, data, length,
transferred, timeout); transferred, timeout);

1
usbutils.h

@ -142,6 +142,7 @@ struct usb_find_devices {
int config; int config;
int interface; int interface;
unsigned int timeout; unsigned int timeout;
uint16_t wMaxPacketSize;
uint16_t latency; uint16_t latency;
int epcount; int epcount;
struct usb_endpoints *eps; struct usb_endpoints *eps;

Loading…
Cancel
Save