Skip to content

Commit

Permalink
Reattach kernel driver when failed to claim interface (libusb#441)
Browse files Browse the repository at this point in the history
Potential execution path may happen if kernel driver successfully detached,
but libusb failed to claim the requested interface.

Otherwise the device remains with detached kernel driver.
  • Loading branch information
Youw committed Aug 14, 2022
1 parent 5e299f4 commit 597160d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@ static int hidapi_initialize_device(hid_device *dev, int config_number, const st
res = libusb_claim_interface(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);

#ifdef DETACH_KERNEL_DRIVER
if (dev->is_driver_detached) {
res = libusb_attach_kernel_driver(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0)
LOG("Failed to reattach the driver to kernel.\n");
}
#endif
return 0;
}

Expand Down

0 comments on commit 597160d

Please sign in to comment.