Quantcast

ftdi_usb_close doesn't re-attach the kernel driver

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ftdi_usb_close doesn't re-attach the kernel driver

Jean-René David
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 <[hidden email]>
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

smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Chris Morgan
On Thu, Jan 21, 2016 at 1:15 PM, Jean-René David <[hidden email]> 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 <[hidden email]>
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 [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Thomas Jarosch
In reply to this post by Jean-René David
Hi Jean-René,

Am 21.01.2016 um 19:15 schrieb Jean-René David:

> 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:
>
> ..
>
> 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.

yes, a new flag would be the way to go.

I also think we should put it into ftdi_usb_close_internal()
since that's the one used by a few other libftdi functions.

Another question is how the system reacts if the kernel module
gets detached and re-attached a few times, f.e. if you call
ftdi_get_usb_strings() since that one currently closes the device.


Do you care to develop a patch for it?
I'll review it then :)

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Loading...