Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67073 )
Change subject: usb_device.c: detach/attach usb kernel driver explicitly ......................................................................
usb_device.c: detach/attach usb kernel driver explicitly
Use `libusb_detach_kernel_driver` and `libusb_attach_kernel_driver` instead of `libusb_auto_detach_kernel_driver` to be compatible with older libusb versions without changing the behavior.
TEST=Build with libusb >= 1.0.9
Change-Id: I1363fea13368b7ac1e9a3829864d06d123c4e157 Signed-off-by: Thomas Heijligen thomas.heijligen@secunet.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/67073 Reviewed-by: Peter Marheine pmarheine@chromium.org Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Edward O'Callaghan quasisec@chromium.org Reviewed-by: Anastasia Klimchuk aklm@chromium.org --- M usb_device.c 1 file changed, 30 insertions(+), 3 deletions(-)
Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved Peter Marheine: Looks good to me, but someone else must approve Anastasia Klimchuk: Looks good to me, approved
diff --git a/usb_device.c b/usb_device.c index b3c966c..c9c8d92 100644 --- a/usb_device.c +++ b/usb_device.c @@ -342,9 +342,11 @@ } }
- ret = LIBUSB(libusb_set_auto_detach_kernel_driver(device->handle, 1)); - if (ret != 0) { - msg_perr("USB: Failed to enable auto kernel driver detach\n"); + ret = LIBUSB(libusb_detach_kernel_driver(device->handle, + device->interface_descriptor->bInterfaceNumber)); + if (ret != 0 && ret != LIBUSB_ERROR_NOT_FOUND && ret != LIBUSB_ERROR_NOT_SUPPORTED) { + msg_perr("Cannot detach the existing usb driver. %s\n", + libusb_error_name(ret)); return ret; }
@@ -355,6 +357,8 @@ if (ret != 0) { msg_perr("USB: Could not claim device interface %d\n", device->interface_descriptor->bInterfaceNumber); + libusb_attach_kernel_driver(device->handle, + device->interface_descriptor->bInterfaceNumber); return ret; }
@@ -384,6 +388,8 @@ if (device->handle != NULL) { libusb_release_interface(device->handle, device->interface_descriptor->bInterfaceNumber); + libusb_attach_kernel_driver(device->handle, + device->interface_descriptor->bInterfaceNumber); libusb_close(device->handle); }