From: Freek Dijkstra Date: Mon, 11 Jan 2021 00:49:42 +0000 (+0100) Subject: MacOS: Silence pipe error in set_interface_alt_setting() X-Git-Tag: upstream/1.0.25~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bf943bce82293a304d71807081233257ff8b955b;p=platform%2Fupstream%2Flibusb.git MacOS: Silence pipe error in set_interface_alt_setting() darwin_set_interface_altsetting() no longer returns the status of the underlying SetAlternateInterface(), but instead the result of a subsequent GetNumEndpoints() call. This reverts to the behaviour prior to commit 065e586. Since darwin_set_interface_altsetting() resets the interface after SetAlternateInterface(), one of the consequences is that if SetAlternateInterface() returns a kIOUSBPipeStalled error, and the interface is successfully reset, darwin_set_interface_altsetting() now returns LIBUSB_SUCCESS instead of LIBUSB_ERROR_PIPE. Closes: #838 Signed-off-by: Freek Dijkstra Signed-off-by: Nathan Hjelm --- diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index e415589..8055cc0 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -1567,8 +1567,15 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand return LIBUSB_ERROR_NO_DEVICE; kresult = (*(cInterface->interface))->SetAlternateInterface (cInterface->interface, altsetting); - if (kresult != kIOReturnSuccess) + /* If a device only supports a default setting for the specified interface, then a STALL + (kIOUSBPipeStalled) may be returned. Ref: USB 2.0 specs 9.4.10. + Mimick the behaviour in e.g. the Linux kernel: in such case, reset all endpoints, + and hide errors.Current implementation resets the entire device, instead of single + interface, due to historic reasons. */ + if (kresult != kIOReturnSuccess) { + usbi_warn (HANDLE_CTX (dev_handle), "SetAlternateInterface: %s", darwin_error_str(kresult)); darwin_reset_device (dev_handle); + } /* update list of endpoints */ ret = get_endpoints (dev_handle, iface); @@ -1576,10 +1583,9 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand /* this should not happen */ darwin_release_interface (dev_handle, iface); usbi_err (HANDLE_CTX (dev_handle), "could not build endpoint table"); - return ret; } - return darwin_to_libusb (kresult); + return ret; } static int darwin_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index c30b57d..ce7c73c 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11591 +#define LIBUSB_NANO 11592