What better way to show how useful libusb_set_auto_detach_kernel_driver() is, then to use it in our examples?
Signed-off-by: Hans de Goede <hdego...@redhat.com> --- examples/fxload.c | 8 +------- examples/xusb.c | 19 +------------------ libusb/version_nano.h | 2 +- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/examples/fxload.c b/examples/fxload.c index d8e9941..14226ca 100644 --- a/examples/fxload.c +++ b/examples/fxload.c @@ -242,14 +242,8 @@ int main(int argc, char*argv[]) } /* We need to claim the first interface */ + libusb_set_auto_detach_kernel_driver(device, 1); status = libusb_claim_interface(device, 0); -#if defined(__linux__) - if (status != LIBUSB_SUCCESS) { - /* Maybe we need to detach the driver */ - libusb_detach_kernel_driver(device, 0); - status = libusb_claim_interface(device, 0); - } -#endif if (status != LIBUSB_SUCCESS) { logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status)); goto err; diff --git a/examples/xusb.c b/examples/xusb.c index 3d3b853..bdb9794 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -785,8 +785,6 @@ static int test_device(uint16_t vid, uint16_t pid) const struct libusb_endpoint_descriptor *endpoint; int i, j, k, r; int iface, nb_ifaces, first_iface = -1; - // For attaching/detaching the kernel driver, if needed - int iface_detached = -1; struct libusb_device_descriptor dev_desc; const char* speed_name[5] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)", "480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)"}; @@ -894,21 +892,11 @@ static int test_device(uint16_t vid, uint16_t pid) } libusb_free_config_descriptor(conf_desc); + libusb_set_auto_detach_kernel_driver(handle, 1); for (iface = 0; iface < nb_ifaces; iface++) { printf("\nClaiming interface %d...\n", iface); r = libusb_claim_interface(handle, iface); - if ((r != LIBUSB_SUCCESS) && libusb_has_capability(LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER) - && (libusb_kernel_driver_active(handle, iface) > 0)) { - // Try to detach the kernel driver - perr(" A kernel driver is active, trying to detach it...\n"); - r = libusb_detach_kernel_driver(handle, iface); - if (r == LIBUSB_SUCCESS) { - iface_detached = iface; - printf(" Claiming interface again...\n"); - r = libusb_claim_interface(handle, iface); - } - } if (r != LIBUSB_SUCCESS) { perr(" Failed.\n"); } @@ -957,11 +945,6 @@ static int test_device(uint16_t vid, uint16_t pid) libusb_release_interface(handle, iface); } - if (iface_detached >= 0) { - printf("Re-attaching kernel driver...\n"); - libusb_attach_kernel_driver(handle, iface_detached); - } - printf("Closing device...\n"); libusb_close(handle); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 1703d21..75ec58f 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10739 +#define LIBUSB_NANO 10740 -- 1.8.2.1 ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel