From 1d8a3fff7dae6761d27bc90db23c33827084003e Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Fri, 7 Jun 2024 12:10:18 -0500 Subject: [PATCH] usb: Attempt detaching kernel driver In the event that the kernel have some other driver attached to the device the attempt claim of the interface will fail. Lost in the libusb conversion was a call to USBDEVFS_DISCONNECT to first detach any such drivers. Reintroduce this by invoking libusb_detach_kernel_driver(). As with some other libusb functions there are multiple return values denoting "success", so rely on libusb_claim_interface() to catch the actual errors. Reported-by: Maxim Akristiniy Suggested-by: Maxim Akristiniy Signed-off-by: Bjorn Andersson --- usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usb.c b/usb.c index f4a0e7c..12d0939 100644 --- a/usb.c +++ b/usb.c @@ -126,6 +126,8 @@ static int qdl_try_open(libusb_device *dev, struct qdl_device *qdl, const char * continue; } + libusb_detach_kernel_driver(handle, ifc->bInterfaceNumber); + ret = libusb_claim_interface(handle, ifc->bInterfaceNumber); if (ret < 0) { warnx("failed to claim USB interface");