Subject: Interrupts in modules

From: Steve Papacharalambous <[email-masked]>
Date: Sat, 21 Jul 2001 23:02:53 +0100

Hi All,

Are there any limitations or precautions needed with interrupt handlers
in loadable modules?

The reason for asking is that I have an interrupt handler which works
fine when compiled into the kernel, but causes the kernel to crash when
it is a loadable module,

Thanks,

Steve

---

From: Keith Owens <[email-masked]>
Date: Sun, 22 Jul 2001 11:17:29 +1000

On Sat, 21 Jul 2001 23:02:53 +0100, 
>Are there any limitations or precautions needed with interrupt handlers

There is a potential race condition when removing the module.  rmmod
will remove a module when its use count is zero.  If the interrupt
handler is invoked after the use count is tested but before the module
cleanup routine is entered then the code can be removed while the
interrupt handler is running.  The 2.5 module load/unload system will
remove this race.

In 2.4, your best option is to set a can_unload() function in the
module.  Unregister the interrupt handler in can_unload(), wait until
the interrupt count goes to zero (might be running on another cpu) then
return 0.  See drivers/char/ftape/compressor/zftape-compress.c for an
example.

Alternatively keep a use count for opens on the device.  This assumes
that the device does not generate interrupts while it is not open, not
always true.

---

From: "H . J . Lu" <[email-masked]>
Date: Sun, 22 Jul 2001 11:28:37 -0700

> fine when compiled into the kernel, but causes the kernel to crash when

There are some gas bugs which may generate the bad binary code. It
happened to me with the tulip driver. The current Linux binutils
should be ok.

H.J.