From: Soeren Apel Date: Mon, 6 Jul 2015 19:20:26 +0000 (+0200) Subject: fx2lafw: Fix #445 by detaching the kernel driver (if any) X-Git-Tag: libsigrok-0.4.0~465 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=39e4517759d391e5572e81d9796d4d8c6892d25e fx2lafw: Fix #445 by detaching the kernel driver (if any) This avoids the need to run "rmmod usbtest" on Linux for devices with the standard Cypress FX2 USB VID/PID (04b4:8613). --- diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index ada4fcc9..724e2dd4 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -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.