From 2abb2a186e6c085396654851f7d18aa20ce2e753 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Thu, 26 Jan 2023 14:02:35 +0100 Subject: xusb: Improve Max LUN retrieval stall handling Do not show an uninitialized Max LUN value if the pipe stalled. As suggested by the code comment (but not the old code), set a default zero value only on pipe stall. On other errors simply error out. References #1181 Closes #1239 Signed-off-by: Tormod Volden --- examples/xusb.c | 9 ++++++--- libusb/version_nano.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/xusb.c b/examples/xusb.c index 7c2abb9..441af01 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -470,12 +470,15 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, BOMS_GET_MAX_LUN, 0, 0, &lun, 1, 1000); // Some devices send a STALL instead of the actual value. // In such cases we should set lun to 0. - if (r == 0) { + if (r == LIBUSB_ERROR_PIPE) { lun = 0; + printf(" Stalled, setting Max LUN to 0\n"); } else if (r < 0) { - perr(" Failed: %s", libusb_strerror((enum libusb_error)r)); + perr(" Failed.\n"); + return r; + } else { + printf(" Max LUN = %d\n", lun); } - printf(" Max LUN = %d\n", lun); // Send Inquiry printf("\nSending Inquiry:\n"); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 4ac20f3..e443da4 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11783 +#define LIBUSB_NANO 11784 -- cgit v1.2.1