Thomas Heijligen has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67071 )
(
3 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: ch341a_spi: detach/attach kernel driver explicitly ......................................................................
ch341a_spi: detach/attach 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 Read spi flash with ch341a programmer on linux
Change-Id: Ia649722e64cc97c6b689dd3b764e5c9145959f92 Signed-off-by: Thomas Heijligen thomas.heijligen@secunet.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/67071 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Edward O'Callaghan quasisec@chromium.org --- M ch341a_spi.c 1 file changed, 26 insertions(+), 5 deletions(-)
Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved
diff --git a/ch341a_spi.c b/ch341a_spi.c index 78b9cee..48c6420 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -398,6 +398,7 @@ transfer_ins[i] = NULL; } libusb_release_interface(handle, 0); + libusb_attach_kernel_driver(handle, 0); libusb_close(handle); libusb_exit(NULL); handle = NULL; @@ -448,11 +449,10 @@ return -1; }
- ret = libusb_set_auto_detach_kernel_driver(handle, 1); - if (ret != 0) { - msg_pwarn("Platform does not support detaching of USB kernel drivers.\n" - "If an unsupported driver is active, claiming the interface may fail.\n"); - } + ret = libusb_detach_kernel_driver(handle, 0); + if (ret != 0 && ret != LIBUSB_ERROR_NOT_FOUND) + msg_pwarn("Cannot detach the existing USB driver. Claiming the interface may fail. %s\n", + libusb_error_name(ret));
ret = libusb_claim_interface(handle, 0); if (ret != 0) { @@ -514,6 +514,7 @@ release_interface: libusb_release_interface(handle, 0); close_handle: + libusb_attach_kernel_driver(handle, 0); libusb_close(handle); handle = NULL; return -1;