sparseirq: make for_each_irq_desc() more robust
authorKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Sat, 3 Jan 2009 18:11:05 +0000 (03:11 +0900)
committerIngo Molnar <mingo@elte.hu>
Wed, 7 Jan 2009 22:18:08 +0000 (23:18 +0100)
Raja reported for_each_irq_desc() has possibility unsafeness:

if anyone write folliwing code, for_each_irq_desc() doesn't work
as intended:

(right now this code does not exist at all)

 if (safe)
   for_each_irq_desc(irq, desc) {
      ...
   }
 else
   panic();

Reported-by: Raja R Harinath <harinath@hurrynot.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/irqnr.h

index 86af92e9e84c0e3115845bcd3abbc125d28b5088..52ebbb4b161d46372ad3c53be48b2e14cf61811a 100644 (file)
@@ -28,13 +28,17 @@ extern struct irq_desc *irq_to_desc(unsigned int irq);
 # define for_each_irq_desc(irq, desc)                                  \
        for (irq = 0, desc = irq_to_desc(irq); irq < nr_irqs;           \
             irq++, desc = irq_to_desc(irq))                            \
-               if (desc)
+               if (!desc)                                              \
+                       ;                                               \
+               else
 
 
 # define for_each_irq_desc_reverse(irq, desc)                          \
        for (irq = nr_irqs - 1, desc = irq_to_desc(irq); irq >= 0;      \
             irq--, desc = irq_to_desc(irq))                            \
-               if (desc)
+               if (!desc)                                              \
+                       ;                                               \
+               else
 
 #endif /* CONFIG_GENERIC_HARDIRQS */