From eae30b2a162dbcfa367d796a11ae45c3a3a7c459 Mon Sep 17 00:00:00 2001 From: Siarhei Siamashka Date: Wed, 4 Feb 2015 20:38:23 +0200 Subject: [PATCH] fel: Fix USB timeout on large transfers Trying to use oversized initrd files (20 MB or more) can fail with the "libusb usb_bulk_send error -1" error message. To address this problem, we can split the transfer into smaller chunks and the problem disappears. Effectively, this is a revert of the older "fel: Increase timeout to 60 seconds instead of splitting bulk transfers" commmit. Signed-off-by: Siarhei Siamashka Acked-by: Hans de Goede --- fel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fel.c b/fel.c index 382b18b..1e44003 100644 --- a/fel.c +++ b/fel.c @@ -73,11 +73,14 @@ static void pr_info(const char *fmt, ...) } } +static const int AW_USB_MAX_BULK_SEND = 4 * 1024 * 1024; // 4 MiB per bulk request + void usb_bulk_send(libusb_device_handle *usb, int ep, const void *data, int length) { int rc, sent; while (length > 0) { - rc = libusb_bulk_transfer(usb, ep, (void *)data, length, &sent, timeout); + int len = length < AW_USB_MAX_BULK_SEND ? length : AW_USB_MAX_BULK_SEND; + rc = libusb_bulk_transfer(usb, ep, (void *)data, len, &sent, timeout); if (rc != 0) { fprintf(stderr, "libusb usb_bulk_send error %d\n", rc); exit(2);