libftdi Archives

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

From: Chris Morgan <chmorgan@xxxxxxxxx>
To: "libftdi@xxxxxxxxxxxxxxxxxxxxxxx" <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 Jan 2016 19:52:04 -0500
On Thu, Jan 21, 2016 at 1:15 PM, Jean-René David <jrdavid@xxxxxx> wrote:
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


I've used this same approach when using libftdi in order to give the device back to the kernel. Glad to see someone bringing it up for consideration back into libftdi. Just throwing it out there but I wondered if it was related to the device possibly being passed directly in, such that it wasn't detatched initially, thus shouldn't be automatically reattached on close.

Chris




libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread