GCAdapter: fix retval check of libusb_detach_kernel_driver

This commit is contained in:
Shawn Hoffman 2022-04-22 08:48:28 -07:00
parent 978c90845b
commit 5cd3cf9072
1 changed files with 4 additions and 2 deletions

View File

@ -335,11 +335,13 @@ static bool CheckDeviceAccess(libusb_device* device)
return false; return false;
} }
bool detach_failed = false;
ret = libusb_kernel_driver_active(s_handle, 0); ret = libusb_kernel_driver_active(s_handle, 0);
if (ret == 1) if (ret == 1)
{ {
ret = libusb_detach_kernel_driver(s_handle, 0); ret = libusb_detach_kernel_driver(s_handle, 0);
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) detach_failed = ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND && ret != LIBUSB_ERROR_NOT_SUPPORTED;
if (detach_failed)
ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret); ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret);
} }
@ -351,7 +353,7 @@ static bool CheckDeviceAccess(libusb_device* device)
// this split is needed so that we don't avoid claiming the interface when // this split is needed so that we don't avoid claiming the interface when
// detaching the kernel driver is successful // detaching the kernel driver is successful
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) if (detach_failed)
{ {
libusb_close(s_handle); libusb_close(s_handle);
s_handle = nullptr; s_handle = nullptr;