Forward port flexible module unload behavior
[libftdi] / src / ftdi.c
index 08b4010..e3201d1 100644 (file)
@@ -105,6 +105,8 @@ int ftdi_init(struct ftdi_context *ftdi)
     memset(eeprom, 0, sizeof(struct ftdi_eeprom));
     ftdi->eeprom = eeprom;
 
+    ftdi->module_detach_mode = AUTO_DETACH_SIO_MODULE;
+
     /* All fine. Now allocate the readbuffer */
     return ftdi_read_data_set_chunksize(ftdi, 4096);
 }
@@ -498,8 +500,11 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, libusb_device *dev)
     // if usb_set_configuration() or usb_claim_interface() fails as the
     // detach operation might be denied and everything still works fine.
     // Likely scenario is a static ftdi_sio kernel module.
-    if (libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface) !=0)
-        detach_errno = errno;
+    if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
+    {
+        if (libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface) !=0)
+            detach_errno = errno;
+    }
 
     if (libusb_get_configuration (ftdi->usb_dev, &cfg) < 0)
         ftdi_error_return(-12, "libusb_get_configuration () failed");