Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[sfrench/cifs-2.6.git] / kernel / irq / handle.c
index 343acecae629ff37c32013daede12da10b21f7fb..26e08754744fa13dd9da3e919be6adb3976b2b04 100644 (file)
@@ -339,6 +339,15 @@ irqreturn_t no_action(int cpl, void *dev_id)
        return IRQ_NONE;
 }
 
+static void warn_no_thread(unsigned int irq, struct irqaction *action)
+{
+       if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
+               return;
+
+       printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
+              "but no thread function available.", irq, action->name);
+}
+
 DEFINE_TRACE(irq_handler_entry);
 DEFINE_TRACE(irq_handler_exit);
 
@@ -354,8 +363,6 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
        irqreturn_t ret, retval = IRQ_NONE;
        unsigned int status = 0;
 
-       WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!");
-
        if (!(action->flags & IRQF_DISABLED))
                local_irq_enable_in_hardirq();
 
@@ -363,8 +370,47 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
                trace_irq_handler_entry(irq, action);
                ret = action->handler(irq, action->dev_id);
                trace_irq_handler_exit(irq, action, ret);
-               if (ret == IRQ_HANDLED)
+
+               switch (ret) {
+               case IRQ_WAKE_THREAD:
+                       /*
+                        * Set result to handled so the spurious check
+                        * does not trigger.
+                        */
+                       ret = IRQ_HANDLED;
+
+                       /*
+                        * Catch drivers which return WAKE_THREAD but
+                        * did not set up a thread function
+                        */
+                       if (unlikely(!action->thread_fn)) {
+                               warn_no_thread(irq, action);
+                               break;
+                       }
+
+                       /*
+                        * Wake up the handler thread for this
+                        * action. In case the thread crashed and was
+                        * killed we just pretend that we handled the
+                        * interrupt. The hardirq handler above has
+                        * disabled the device interrupt, so no irq
+                        * storm is lurking.
+                        */
+                       if (likely(!test_bit(IRQTF_DIED,
+                                            &action->thread_flags))) {
+                               set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
+                               wake_up_process(action->thread);
+                       }
+
+                       /* Fall through to add to randomness */
+               case IRQ_HANDLED:
                        status |= action->flags;
+                       break;
+
+               default:
+                       break;
+               }
+
                retval |= ret;
                action = action->next;
        } while (action);