libftdi Archives

Subject: ftdi_usb_close doesn't re-attach the kernel driver

From: Jean-René David <jrdavid@xxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 21 Jan 2016 13:15:59 -0500
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 <jrdavid@xxxxxx>
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

Current Thread