Check length before submitting sync transfers
diff --git a/usbutils.c b/usbutils.c
index 130331c..ca850c7 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2436,13 +2436,14 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
usb_epinfo = &(cgpu->usbdev->found->intinfos[intinfo].epinfos[epinfo]);
endpoint = usb_epinfo->ep;
+ if (length > usb_epinfo->wMaxPacketSize)
+ length = usb_epinfo->wMaxPacketSize;
+
/* Avoid any async transfers during shutdown to allow the polling
* thread to be shut down after all existing transfers are complete */
if (unlikely(cgpu->shutdown))
return libusb_bulk_transfer(dev_handle, endpoint, data, length, transferred, timeout);
- if (length > usb_epinfo->wMaxPacketSize)
- length = usb_epinfo->wMaxPacketSize;
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
memcpy(buf, data, length);