Anastasia Klimchuk submitted this change.

View Change


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
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(-)

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);
}


To view, visit change 67073. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I1363fea13368b7ac1e9a3829864d06d123c4e157
Gerrit-Change-Number: 67073
Gerrit-PatchSet: 6
Gerrit-Owner: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus@gmail.com>
Gerrit-MessageType: merged