Added check to only detach kernel driver in LighpackDevice when it is active in the first place

Former-commit-id: 99e68e88571510bfb07a82942ee3f975f3f86a7f
This commit is contained in:
johan 2013-11-18 21:13:32 +01:00
parent aa318d5822
commit f5f1019f72
2 changed files with 10 additions and 6 deletions

View File

@ -1 +1 @@
b4ecb001b419687ffbef1bebb7c274bb31ea55f1
d59ae219a9dad5cd6138c23122df5e3313e473cb

View File

@ -302,12 +302,16 @@ libusb_device_handle * LedDeviceLightpack::openDevice(libusb_device *device)
throw error;
}
error = libusb_detach_kernel_driver(handle, LIGHTPACK_INTERFACE);
if (error != LIBUSB_SUCCESS)
// detach kernel driver if it is active
if (libusb_kernel_driver_active(handle, LIGHTPACK_INTERFACE) == 1)
{
std::cerr << "unable to detach kernel driver(" << error << "): " << libusb_error_name(error) << std::endl;
libusb_close(handle);
throw error;
error = libusb_detach_kernel_driver(handle, LIGHTPACK_INTERFACE);
if (error != LIBUSB_SUCCESS)
{
std::cerr << "unable to detach kernel driver(" << error << "): " << libusb_error_name(error) << std::endl;
libusb_close(handle);
throw error;
}
}
error = libusb_claim_interface(handle, LIGHTPACK_INTERFACE);