libusb: Add auto-detach-kernel-driver functionality
authorHans de Goede <hdegoede@redhat.com>
Thu, 13 Jun 2013 19:21:14 +0000 (21:21 +0200)
committerHans de Goede <hdegoede@redhat.com>
Wed, 19 Jun 2013 09:04:14 +0000 (11:04 +0200)
commitfc51f19341af70508b94c06ff763842b396ea72e
tree0cb2d75131893603a3e4c0c456f4cefe060599ca
parent6b3931526db981e3a298a226e5d0b4e20c04913d
libusb: Add auto-detach-kernel-driver functionality

Add auto-detach-kernel-driver functionality, and a
libusb_set_auto_detach_kernel_driver() function.

Note that I went with a libusb_set_auto_detach_kernel_driver() function,
rather then with a libusb_enable_auto_detach_kernel_driver(), so that apps
can also disable it again. This is necessary to handle 2 corner cases:

1) When an app wants to do a libusb_set_configuration after claiming 1 or
more interfaces, it needs to first release the interface(s), and in this
case libusb_release_interface() should *not* (re-)attach the kernel driver

2) Some usb classes use multiple interfaces for one function, ie usb-audio
devices do this. In this case attaching the driver will fail until all
interfaces are released, so the app should first release all interfaces, and
only then (re-)attach the kernel driver.

auto-detach-kernel-driver functionality is still useful for these apps, since
doing libusb_detach_kernel_driver() followed by libusb_claim_interface() in
2 separate calls is inherently racy, but they need to be able to disable the
auto-detach functionality before releasing interfaces to be able to properly
handle the 2 described corner cases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/core.c
libusb/libusb-1.0.def
libusb/libusb.h
libusb/libusbi.h
libusb/os/linux_usbfs.c
libusb/version_nano.h