]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Fix #445 by detaching the kernel driver (if any)
authorSoeren Apel <redacted>
Mon, 6 Jul 2015 19:20:26 +0000 (21:20 +0200)
committerUwe Hermann <redacted>
Thu, 9 Jul 2015 23:03:54 +0000 (01:03 +0200)
This avoids the need to run "rmmod usbtest" on Linux for devices
with the standard Cypress FX2 USB VID/PID (04b4:8613).

src/hardware/fx2lafw/api.c

index ada4fcc9b002989572ce5005366fad7636cc35f5..724e2dd4e2ee0eb63b9ca3d723759c04eaf634f0 100644 (file)
@@ -370,6 +370,16 @@ static int dev_open(struct sr_dev_inst *sdi)
        devc = sdi->priv;
        usb = sdi->conn;
 
+       if (libusb_has_capability(LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER)) {
+               if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) {
+                       if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) {
+                               sr_err("Failed to detach kernel driver: %s.",
+                                       libusb_error_name(ret));
+                               return SR_ERR;
+                       }
+               }
+       }
+
        /*
         * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
         * milliseconds for the FX2 to renumerate.