audiohacked / OpenCorsairLink

Linux and Mac OS support for the CorsairLink Devices
GNU General Public License v2.0
705 stars 125 forks source link

Set libusb to automatically detach/attach the kernel driver #199

Closed jonasmalacofilho closed 5 years ago

jonasmalacofilho commented 5 years ago

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.

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

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.