]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Fix segfault wrt libusb_detach_kernel_driver().
authorUwe Hermann <redacted>
Thu, 9 Jul 2015 22:59:48 +0000 (00:59 +0200)
committerUwe Hermann <redacted>
Thu, 9 Jul 2015 23:05:54 +0000 (01:05 +0200)
Move the libusb_detach_kernel_driver() call after the code that
sets the usb->devhdl pointer, otherwise it'll be NULL and result
in a segfault.

  #0  libusb_kernel_driver_active (dev=0x0, interface_number=0) at libusb/core.c:1711
  #1  dev_open (sdi=0x12d99f0) at src/hardware/fx2lafw/api.c:374
  [...]

Tested on a device with the default Cypress VID/PID and one with
the Saleae Logic VID/PID, both works fine.

src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/protocol.c

index 724e2dd4e2ee0eb63b9ca3d723759c04eaf634f0..ada4fcc9b002989572ce5005366fad7636cc35f5 100644 (file)
@@ -370,16 +370,6 @@ 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.
index 11e3504e7948b7b6a8899fe51f9e601d85181ab5..b1c20a7159b2f3794dc29047c49b041bb325ca5c 100644 (file)
@@ -244,6 +244,16 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
                        break;
                }
 
+               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;
+                               }
+                       }
+               }
+
                ret = command_get_fw_version(usb->devhdl, &vi);
                if (ret != SR_OK) {
                        sr_err("Failed to get firmware version.");