Browse Source

Always use a maxpacketsize buffer in usb_bulk_transfer

Con Kolivas 12 years ago
parent
commit
b1823f2723
1 changed files with 6 additions and 0 deletions
  1. 6 0
      usbutils.c

+ 6 - 0
usbutils.c

@@ -2286,6 +2286,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 #if DO_USB_STATS
 #if DO_USB_STATS
 	struct timeval tv_start, tv_finish;
 	struct timeval tv_start, tv_finish;
 #endif
 #endif
+	unsigned char *buf;
 
 
 	/* Limit length of transfer to the largest this descriptor supports
 	/* Limit length of transfer to the largest this descriptor supports
 	 * and leave the higher level functions to transfer more if needed. */
 	 * and leave the higher level functions to transfer more if needed. */
@@ -2295,6 +2296,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 		MaxPacketSize = cgpu->usbdev->found->wMaxPacketSize;
 		MaxPacketSize = cgpu->usbdev->found->wMaxPacketSize;
 	if (length > MaxPacketSize)
 	if (length > MaxPacketSize)
 		length = MaxPacketSize;
 		length = MaxPacketSize;
+	buf = alloca(MaxPacketSize);
+	if (endpoint == LIBUSB_ENDPOINT_OUT)
+		memcpy(buf, data, length);
 
 
 	STATS_TIMEVAL(&tv_start);
 	STATS_TIMEVAL(&tv_start);
 	cg_rlock(&cgusb_fd_lock);
 	cg_rlock(&cgusb_fd_lock);
@@ -2346,6 +2350,8 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle,
 		if (err)
 		if (err)
 			cgpu->usbinfo.clear_fail_count++;
 			cgpu->usbinfo.clear_fail_count++;
 	}
 	}
+	if (endpoint == LIBUSB_ENDPOINT_OUT)
+		memcpy(data, buf, length);
 
 
 	return err;
 	return err;
 }
 }