Convert libusb transfer errors to regular libusb error messages to allow for accurate message reporting.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/usbutils.c b/usbutils.c
index 2e160ad..963cc50 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2232,6 +2232,33 @@ static void LIBUSB_CALL transfer_callback(struct libusb_transfer *transfer)
cgsem_post(&ut->cgsem);
}
+static int usb_transfer_toerr(int ret)
+{
+ switch (ret) {
+ default:
+ case LIBUSB_TRANSFER_COMPLETED:
+ ret = LIBUSB_SUCCESS;
+ break;
+ case LIBUSB_TRANSFER_ERROR:
+ ret = LIBUSB_ERROR_IO;
+ break;
+ case LIBUSB_TRANSFER_TIMED_OUT:
+ case LIBUSB_TRANSFER_CANCELLED:
+ ret = LIBUSB_ERROR_TIMEOUT;
+ break;
+ case LIBUSB_TRANSFER_STALL:
+ ret = LIBUSB_ERROR_PIPE;
+ break;
+ case LIBUSB_TRANSFER_NO_DEVICE:
+ ret = LIBUSB_ERROR_NO_DEVICE;
+ break;
+ case LIBUSB_TRANSFER_OVERFLOW:
+ ret = LIBUSB_ERROR_OVERFLOW;
+ break;
+ }
+ return ret;
+}
+
/* Wait for callback function to tell us it has finished the USB transfer, but
* use our own timer to cancel the request if we go beyond the timeout. */
static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int timeout)
@@ -2248,8 +2275,7 @@ static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int
cgsem_wait(&ut->cgsem);
}
ret = transfer->status;
- if (ret == LIBUSB_TRANSFER_CANCELLED || ret == LIBUSB_TRANSFER_TIMED_OUT)
- ret = LIBUSB_ERROR_TIMEOUT;
+ ret = usb_transfer_toerr(ret);
/* No need to sort out mutexes here since they won't be reused */
*transferred = transfer->actual_length;
@@ -2316,7 +2342,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
cgpu->drv->name, cgpu->device_id,
usb_cmdname(cmd), *transferred, err, errn);
- if (err == LIBUSB_ERROR_PIPE || err == LIBUSB_TRANSFER_STALL) {
+ if (err == LIBUSB_ERROR_PIPE) {
int retries = 0;
do {
@@ -2739,15 +2765,14 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de
err = libusb_submit_transfer(ut.transfer);
if (!err)
err = callback_wait(&ut, &transferred, timeout);
- if (err == LIBUSB_TRANSFER_COMPLETED && transferred) {
+ if (err == LIBUSB_SUCCESS && transferred) {
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
memcpy(buffer, libusb_control_transfer_get_data(ut.transfer),
transferred);
err = transferred;
goto out;
}
- if ((err) == LIBUSB_TRANSFER_CANCELLED)
- err = LIBUSB_ERROR_TIMEOUT;
+ err = usb_transfer_toerr(err);
out:
complete_usb_transfer(&ut);
return err;