From 5903bb829d8bf67aee290ff4ef141fd76507767c Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Thu, 25 Aug 2022 13:05:39 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/67071 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan --- ch341a_spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ch341a_spi.c') diff --git a/ch341a_spi.c b/ch341a_spi.c index 78b9cee6..48c64207 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -398,6 +398,7 @@ static int ch341a_spi_shutdown(void *data) 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 @@ static int ch341a_spi_init(const struct programmer_cfg *cfg) 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 @@ dealloc_transfers: release_interface: libusb_release_interface(handle, 0); close_handle: + libusb_attach_kernel_driver(handle, 0); libusb_close(handle); handle = NULL; return -1; -- cgit v1.2.3