Hello,

I noticed that after calling ftdi_usb_open() on a device, the kernel driver is 
left detached despite calling ftdi_usb_close() and using AUTO_DETACH_SIO_MODULE.

Given the comment in the definition of AUTO_DETACH_SIO_MODULE in src/ftdi.h:

/** Automatic loading / unloading of kernel modules */
enum ftdi_module_detach_mode
{
    AUTO_DETACH_SIO_MODULE = 0,
    DONT_DETACH_SIO_MODULE = 1
};

I wonder if ftdi_usb_close() should re-attach the driver like so:

commit c99b4896892729050feb043dc5fa8e2ea9b8814b (HEAD -> master, pi/master)
Author: Jean-Rene David <[email protected] <mailto:[email protected]>>
Date:   2016-01-20 19:52:30 +0000

   Re-attach kernel driver

diff --git src/ftdi.c src/ftdi.c
index aa4b4ec..7891b91 100644
--- src/ftdi.c
+++ src/ftdi.c
@@ -995,6 +995,9 @@ int ftdi_usb_close(struct ftdi_context *ftdi)
        if (libusb_release_interface(ftdi->usb_dev, ftdi->interface) < 0)
            rtn = -1;

+    if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
+        libusb_attach_kernel_driver(ftdi->usb_dev, ftdi->interface);
+
    ftdi_usb_close_internal (ftdi);

    return rtn;

Maybe creating a new flag to re-attach would be safer, to avoid breaking 
existing programs.

-- 
JR

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to