7
votes

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?

1

1 Answers

9
votes

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.