Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it necessary to mark interrupt handler functions as static?

While reading "Linux kernel development" by Robert Love, I found at page 119:

The interrupt handler is normally marked static because it is never called directly from another file.

For example:

static irqreturn_t intr_handler(int irq, void *dev)

But why it is so? I doubt this function is going to be called by the kernel and if we make it static, then how is the kernel going to call it?

like image 642
pradipta Avatar asked Jul 22 '13 06:07

pradipta


1 Answers

According to this, the way the function is used is by "registering" it with the kernel. That is, there's a function such as InstallIntHdlr which you call and pass a pointer to your handler. The kernel can then use that pointer to call the function itself.

My guess, though I'm not sure about this, is that static is used as a way of enforcing the proper usage of an interrupt handler. That is, since static functions can't be called from other files, it forces you to pass a pointer to it instead of calling it directly.

like image 135
joshlf Avatar answered Sep 18 '22 18:09

joshlf