Both libusb_detach_kernel_driver and libusb_attach_kernel_driver are
perfectly fine to return errors if there was no kernel bound to the
device in the first place.
Instead of tracking that ourselves, just set libusb to do it automatically.
When this is enabled libusb will automatically detach the kernel driver
on an interface when claiming the interface, and attach it when
releasing the interface.
libusb_set_auto_detach_kernel_driver will only fail if on that platform
libusb cannot detach a kernel driver in the first place. As this can
happen simply because detaching the kernel driver is not required for
libusb to work on the platform, only emit a warning but carry on.
This patch was tested on Linux with a dummy device (not from Corsair,
but compatible with the Asetek code), both with and without having a
kernel driver bound to it first.
Fixes: #193
Related: #134
Types of changes
What types of changes does your code introduce to Appium?
Put an x in the boxes that apply
[x] Bugfix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
Proposed changes
Both libusb_detach_kernel_driver and libusb_attach_kernel_driver are perfectly fine to return errors if there was no kernel bound to the device in the first place.
Instead of tracking that ourselves, just set libusb to do it automatically.
libusb_set_auto_detach_kernel_driver will only fail if on that platform libusb cannot detach a kernel driver in the first place. As this can happen simply because detaching the kernel driver is not required for libusb to work on the platform, only emit a warning but carry on.
This patch was tested on Linux with a dummy device (not from Corsair, but compatible with the Asetek code), both with and without having a kernel driver bound to it first.
Fixes: #193 Related: #134
Types of changes
What types of changes does your code introduce to Appium? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.