Hi all,

This is a forward of a mail of mine containing a fix, this was meant to
be sent to the list, but I'm not used to reply to being set to the
sender not the list so i send it to myself.

In the meanwhile I've also had some discussion about this with:
Michael Barabanov <[EMAIL PROTECTED]>

He said this was fixed in 3.0pre8, and it is indeed. He has fixed it in
the exact same way as the fix in the forward, so this problem is solved.

If you think you might be bitten by this and want to stick to 2.2 just
apply the attached patch since it does the exact same thing as the fix
in 3.0pre8 it should be safe.

Regards,

Hans


Hi all,

I've attached a patch which fixes the problem described in my previous
way in the following way:

It adds a rtf_create2 which has a struct module * as third argument.
It changes rtf_create into a macro calling rtf_create2 with
&__this_module as third argument.

This third argument is then used with __MOD_INC_USE_COUNT and
__MOD_DEC_USE_COUNT when an userspace app opens /closes the fifo. This
way the rttask module can't be unloaded when a userspace app has any of
its fifo's open, stopping the described problem.

This means that you can't stop a realtime task without first stopping
all userspace tasks using its fifo's I don't know if this is desirable.
If not then maybe the macro should be taken away so that the coder can
choose wether he wants the problems with the old way, or the less
flexible but more safe new way.

Regards,

Hans
--- rtlinux-2.2/include/rtl_fifo.h.hdg  Wed Feb 23 23:07:24 2000
+++ rtlinux-2.2/include/rtl_fifo.h      Thu Sep  7 15:23:11 2000
@@ -15,6 +15,8 @@
 
 #ifdef __KERNEL__
 
+#include <linux/module.h>
+
 extern int rtf_init(void);
 
 extern int rtf_create_handler(unsigned int fifo, int (*handler)(unsigned int fifo));
@@ -28,7 +30,10 @@
 
 
 
-extern int rtf_create(unsigned int fifo, int size);
+/* extern int rtf_create(unsigned int fifo, int size); */
+#define rtf_create(fifo,size) rtf_create2(fifo, size, &__this_module)
+
+extern int rtf_create2(unsigned int fifo, int size, struct module *mod);
 
 extern int rtf_destroy(unsigned int fifo);
 
--- rtlinux-2.2/fifos/rtl_fifo.c.hdg    Wed Feb 23 23:07:24 2000
+++ rtlinux-2.2/fifos/rtl_fifo.c        Tue Oct 31 15:00:43 2000
@@ -29,6 +29,7 @@
 #include <rtl_fifo.h>
 #include <rtl_core.h>
 
+#undef rtf_create
 
 #ifdef __SMP__
 spinlock_t fifo_spinlock;
@@ -50,6 +51,7 @@
 #else
        struct wait_queue *wait;
 #endif
+        struct module *mod;
 };
 
 static struct rt_fifo_struct fifos[RTF_MAX_FIFO];
@@ -69,6 +71,7 @@
 #define RTF_LEN(minor)         (RTF_ADDR(minor)->len)
 #define RTF_FREE(minor)                (RTF_BUF(minor) - RTF_LEN(minor))
 #define RTF_WAIT(minor)                (RTF_ADDR(minor)->wait)
+#define RTF_MOD(minor)         (RTF_ADDR(minor)->mod)
 
 #define RTF_WRAP(minor,pos)    ((pos) < RTF_BUF(minor)? (pos) : (pos) - 
RTF_BUF(minor))
 #define RTF_END(minor)         RTF_WRAP(minor, RTF_START(minor)+RTF_LEN(minor))
@@ -162,6 +165,11 @@
 
 int rtf_create(unsigned int minor, int size)
 {
+   return rtf_create2(minor, size, NULL);
+}
+
+int rtf_create2(unsigned int minor, int size, struct module *mod)
+{
        int ret;
 
        if (minor >= RTF_MAX_FIFO) {
@@ -184,6 +192,7 @@
 #else
        init_waitqueue (&RTF_WAIT(minor));
 #endif
+        RTF_MOD(minor) = mod;
        RTF_ALLOCATED(minor) = 1;
 
        return 0;
@@ -344,7 +353,10 @@
                return -EACCES;
        }
        RTF_USER_OPEN(minor) = 1;
-
+       if(RTF_MOD(minor))
+       {
+          __MOD_INC_USE_COUNT(RTF_MOD(minor));
+       }
        MOD_INC_USE_COUNT;
        return 0;
 }
@@ -359,6 +371,10 @@
                return 0;  /* that was just a warning */
        }
        RTF_USER_OPEN(minor) = 0;
+       if(RTF_MOD(minor))
+       {
+          __MOD_DEC_USE_COUNT(RTF_MOD(minor));
+       }
        MOD_DEC_USE_COUNT;
        return 0;
 }


Reply via email to