Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

genirq: Switch to irq_get_nr_irqs()

Use the irq_get_nr_irqs() function instead of the global variable
'nr_irqs'. Cache the result of this function in a local variable in
order not to rely on CSE (common subexpression elimination). Prepare
for changing 'nr_irqs' from an exported global variable into a variable
with file scope.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20241015190953.1266194-22-bvanassche@acm.org

authored by

Bart Van Assche and committed by
Thomas Gleixner
1ad2048b f4dd946c

+22 -16
+19 -14
include/linux/irqnr.h
··· 11 11 extern struct irq_desc *irq_to_desc(unsigned int irq); 12 12 unsigned int irq_get_next_irq(unsigned int offset); 13 13 14 - # define for_each_irq_desc(irq, desc) \ 15 - for (irq = 0, desc = irq_to_desc(irq); irq < nr_irqs; \ 16 - irq++, desc = irq_to_desc(irq)) \ 17 - if (!desc) \ 18 - ; \ 19 - else 20 - 14 + #define for_each_irq_desc(irq, desc) \ 15 + for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__; \ 16 + __nr_irqs__ = 0) \ 17 + for (irq = 0, desc = irq_to_desc(irq); irq < __nr_irqs__; \ 18 + irq++, desc = irq_to_desc(irq)) \ 19 + if (!desc) \ 20 + ; \ 21 + else 21 22 22 23 # define for_each_irq_desc_reverse(irq, desc) \ 23 - for (irq = nr_irqs - 1, desc = irq_to_desc(irq); irq >= 0; \ 24 - irq--, desc = irq_to_desc(irq)) \ 24 + for (irq = irq_get_nr_irqs() - 1, desc = irq_to_desc(irq); \ 25 + irq >= 0; irq--, desc = irq_to_desc(irq)) \ 25 26 if (!desc) \ 26 27 ; \ 27 28 else 28 29 29 - # define for_each_active_irq(irq) \ 30 - for (irq = irq_get_next_irq(0); irq < nr_irqs; \ 31 - irq = irq_get_next_irq(irq + 1)) 30 + #define for_each_active_irq(irq) \ 31 + for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__; \ 32 + __nr_irqs__ = 0) \ 33 + for (irq = irq_get_next_irq(0); irq < __nr_irqs__; \ 34 + irq = irq_get_next_irq(irq + 1)) 32 35 33 - #define for_each_irq_nr(irq) \ 34 - for (irq = 0; irq < nr_irqs; irq++) 36 + #define for_each_irq_nr(irq) \ 37 + for (unsigned int __nr_irqs__ = irq_get_nr_irqs(); __nr_irqs__; \ 38 + __nr_irqs__ = 0) \ 39 + for (irq = 0; irq < __nr_irqs__; irq++) 35 40 36 41 #endif
+1 -1
kernel/irq/irqdomain.c
··· 1225 1225 virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE, 1226 1226 affinity); 1227 1227 } else { 1228 - hint = hwirq % nr_irqs; 1228 + hint = hwirq % irq_get_nr_irqs(); 1229 1229 if (hint == 0) 1230 1230 hint++; 1231 1231 virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
+2 -1
kernel/irq/proc.c
··· 457 457 } 458 458 459 459 #ifndef ACTUAL_NR_IRQS 460 - # define ACTUAL_NR_IRQS nr_irqs 460 + # define ACTUAL_NR_IRQS irq_get_nr_irqs() 461 461 #endif 462 462 463 463 int show_interrupts(struct seq_file *p, void *v) 464 464 { 465 + const unsigned int nr_irqs = irq_get_nr_irqs(); 465 466 static int prec; 466 467 467 468 int i = *(loff_t *) v, j;