fx2lafw: Fix segfault wrt libusb_detach_kernel_driver().

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.
This commit is contained in:
Uwe Hermann 2015-07-10 00:59:48 +02:00
parent 39e4517759
commit dc2903bbdb
2 changed files with 10 additions and 10 deletions

View 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.

View 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.");