libftdi Archives

Subject: [PATCH] make module-unloading behavior flexible

From: Thomas Klose <thomas.klose@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Fri, 20 May 2011 17:02:05 +0200
Am Dienstag, den 17.05.2011, 15:34 +0200 schrieb Thomas Jarosch: 
> On 05/13/2011 06:30 PM, Thomas Klose wrote:
> >> I thought about releasing libftdi 0.19 next week.
> >> Any outstanding issues/patches?
> > 
> > Is there a solution for the module-unload-issue?
> > 
> > http://www.mail-archive.com/libftdi@xxxxxxxxxxxxxxxxxxxxxxx/msg01038.html
> > 
> > I am not interested in reopening the discussion. I am just asking. :)
> 
> Nobody stepped up and developed the proposed code change, so I guess
> it will stay in it's current mode, at least for libftdi 0.19.

I hope it is not to late for a patch. Here is my suggestion for a more
flexible module-unloading behavior. The enumeration makes it extensible
for future needs, e.g. "AUTO_REATTACH_SIO_MODULE".


Signed-off-by: Thomas Klose <thomas.klose@xxxxxxxxxxxxx>
---
src/ftdi.c |    9 +++++++--
src/ftdi.h |   10 ++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index e7e91f9..1816ecb 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -123,6 +123,8 @@ int ftdi_init(struct ftdi_context *ftdi)

     ftdi->eeprom_size = FTDI_DEFAULT_EEPROM_SIZE;

+    ftdi->module_detach_mode = AUTO_DETACH_SIO_MODULE;
+
     /* All fine. Now allocate the readbuffer */
     return ftdi_read_data_set_chunksize(ftdi, 4096);
}
@@ -471,8 +473,11 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi,
struct usb_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 (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) !=
0 && errno != ENODATA)
-        detach_errno = errno;
+    if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
+    {
+        if (usb_detach_kernel_driver_np(ftdi->usb_dev,
ftdi->interface) != 0 && errno != ENODATA)
+            detach_errno = errno;
+    }
#endif

#ifdef __WIN32__
diff --git a/src/ftdi.h b/src/ftdi.h
index 0d94526..3e7d43d 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -56,6 +56,13 @@ enum ftdi_interface
     INTERFACE_D   = 4
};

+/** Automatic loading / unloading of kernel modules */
+enum ftdi_module_detach_mode
+{
+    AUTO_DETACH_SIO_MODULE = 0,
+    DONT_DETACH_SIO_MODULE = 1
+};
+
/* Shifting commands IN MPSSE Mode*/
#define MPSSE_WRITE_NEG 0x01   /* Write TDI/DO on negative TCK/SK edge*/
#define MPSSE_BITMODE   0x02   /* Write bits, not bytes */
@@ -216,6 +223,9 @@ struct ftdi_context
     char *async_usb_buffer;
     /** Number of URB-structures we can buffer */
     unsigned int async_usb_buffer_size;
+
+    /** Defines behavior in case a kernel module is already attached to
the device */
+    enum ftdi_module_detach_mode module_detach_mode;
};

/**
-- 
1.7.1



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

Current Thread