From e9a52c03ae3fecb51b882a807c427f4b4dfa2d1e Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Thu, 17 Sep 2015 22:27:22 -0700 Subject: linux_usbfs: Add support for kernels that can reap after disconnect For kernels that support the REAP_AFTER_DISCONNECT capability, it is no longer necessary to use the nasty workaround that is the usbi_handle_disconnect() function. All transfers can be properly reaped as one would expect and will have an appropriate URB status. Note that moving usbi_handle_disconnect() after the hotplug section is fine because the hotplug disconnect message simply gets added to the hotplug_msgs list to be processed the next time handle_events() is called. Signed-off-by: Chris Dickens --- libusb/os/linux_usbfs.c | 8 ++++++-- libusb/os/linux_usbfs.h | 1 + libusb/version_nano.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 1bfcdd0..0fc8083 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -2607,7 +2607,7 @@ static int op_handle_events(struct libusb_context *ctx, * doesn't try to remove it a second time */ usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->fd); hpriv->fd_removed = 1; - usbi_handle_disconnect(handle); + /* device will still be marked as attached if hotplug monitor thread * hasn't processed remove event yet */ usbi_mutex_static_lock(&linux_hotplug_lock); @@ -2615,7 +2615,11 @@ static int op_handle_events(struct libusb_context *ctx, linux_device_disconnected(handle->dev->bus_number, handle->dev->device_address, NULL); usbi_mutex_static_unlock(&linux_hotplug_lock); - continue; + + if (!(hpriv->caps & USBFS_CAP_REAP_AFTER_DISCONNECT)) { + usbi_handle_disconnect(handle); + continue; + } } do { diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h index 43fe11b..7f397f9 100644 --- a/libusb/os/linux_usbfs.h +++ b/libusb/os/linux_usbfs.h @@ -125,6 +125,7 @@ struct usbfs_hub_portinfo { #define USBFS_CAP_BULK_CONTINUATION 0x02 #define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04 #define USBFS_CAP_BULK_SCATTER_GATHER 0x08 +#define USBFS_CAP_REAP_AFTER_DISCONNECT 0x10 #define USBFS_DISCONNECT_CLAIM_IF_DRIVER 0x01 #define USBFS_DISCONNECT_CLAIM_EXCEPT_DRIVER 0x02 diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 031f02e..f7892d2 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11009 +#define LIBUSB_NANO 11010 -- cgit v1.2.1