irqdomain: do not shadow nr_irqs global definition
PATCH 1/1 irqdomain: do not shadow nr_irqs global definition
include/linux/irqnr.h declares a global variable named `nr_irqs'.
The inline function irq_domain_alloc_irqs() from include/linux/irqdomain.h also uses the same name and thus shadow the global declaration. Rename the function argument from nr_irqs' to nbr_irqs'.
This patch silences below -Wshadow warning:
| In file included from ./arch/x86/include/asm/irqdomain.h:5, | from ./arch/x86/include/asm/msi.h:5, | from ./include/linux/msi.h:23, | from ./include/linux/kvm_host.h:19, | from arch/x86/kernel/../kvm/vmx/vmx.h:5, | from arch/x86/kernel/asm-offsets.c:22: | ./include/linux/irqdomain.h: In function 'irq_domain_alloc_irqs': | ./include/linux/irqdomain.h:514:38: warning: declaration of 'nr_irqs' shadows a global declaration [-Wshadow] | 514 | unsigned int nr_irqs, int node, void *arg) | | ~~~~~~~~~~~~~^~~~~~~ | In file included from ./include/linux/interrupt.h:10, | from ./include/linux/kernel_stat.h:9, | from ./include/linux/cgroup.h:26, | from ./include/linux/memcontrol.h:13, | from ./include/linux/swap.h:9, | from ./include/linux/suspend.h:5, | from arch/x86/kernel/asm-offsets.c:13: | ./include/linux/irqnr.h:8:12: note: shadowed declaration is here | 8 | extern int nr_irqs; | | ^~~~~~~
--- include/linux/irqdomain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/irqdomain.h +2 -2
@@ -511,9 +511,9 @@ extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);extern void irq_domain_deactivate_irq (struct irq_data *irq_data);static inline int irq_domain_alloc_irqs (struct irq_domain *domain, -unsigned int nr_irqs,int node,void *arg) +unsigned int nbr_irqs,int node,void *arg) { -return __irq_domain_alloc_irqs (domain,-1 , nr_irqs, node, arg, false, +return __irq_domain_alloc_irqs (domain,-1 , nbr_irqs, node, arg, false,NULL ); }
Signature · 1 line
2.35.1
Quoted 52 lines · Vincent Mailhol
include/linux/irqnr.hdeclares a global variable named `nr_irqs'.The inline function
irq_domain_alloc_irqs()frominclude/linux/irqdomain.halso uses the same name and thus shadow the global declaration. Rename the function argument fromnr_irqs' tonbr_irqs'.This patch silences below -Wshadow warning:
| In file included from ./arch/x86/include/asm/irqdomain.h:5, | from ./arch/x86/include/asm/msi.h:5, | from ./include/linux/msi.h:23, | from ./include/linux/kvm_host.h:19, | from arch/x86/kernel/../kvm/vmx/vmx.h:5, | from arch/x86/kernel/asm-offsets.c:22: | ./include/linux/irqdomain.h: In function 'irq_domain_alloc_irqs': | ./include/linux/irqdomain.h:514:38: warning: declaration of 'nr_irqs' shadows a global declaration [-Wshadow] | 514 | unsigned int nr_irqs, int node, void *arg) | | ~~~~~~~~~~~~~^~~~~~~ | In file included from ./include/linux/interrupt.h:10, | from ./include/linux/kernel_stat.h:9, | from ./include/linux/cgroup.h:26, | from ./include/linux/memcontrol.h:13, | from ./include/linux/swap.h:9, | from ./include/linux/suspend.h:5, | from arch/x86/kernel/asm-offsets.c:13: | ./include/linux/irqnr.h:8:12: note: shadowed declaration is here | 8 | extern int nr_irqs; | | ^~~~~~~Signed-off-by Vincent Mailhol <[email protected]>--- include/linux/irqdomain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/irqdomain.h +2
-2@@ -511,9 +511,9 @@ extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);extern void irq_domain_deactivate_irq (struct irq_data *irq_data);static inline int irq_domain_alloc_irqs (struct irq_domain *domain, -unsigned int nr_irqs,int node,void *arg) +unsigned int nbr_irqs,int node,void *arg) { -return __irq_domain_alloc_irqs (domain,-1 , nr_irqs, node, arg, false, +return __irq_domain_alloc_irqs (domain,-1 , nbr_irqs, node, arg, false,NULL );
Quoted 1 line
}
I really don't think this is worth it. A function has its own namespace, and this warning is on the long list of "this is completely silly". Case in point:
$ git grep 'unsigned int nr_irqs'| wc -l 207
Is anything broken? Not as far as I can tell.
If there was anything to fix, it is the top-level definition that should be more indicative of its global status. But again, there is nothing broken so far.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 60 lines · Marc Zyngier
Quoted 53 lines · Vincent Mailhol
include/linux/irqnr.hdeclares a global variable named `nr_irqs'.The inline function
irq_domain_alloc_irqs()frominclude/linux/irqdomain.halso uses the same name and thus shadow the global declaration. Rename the function argument fromnr_irqs' tonbr_irqs'.This patch silences below -Wshadow warning:
| In file included from ./arch/x86/include/asm/irqdomain.h:5, | from ./arch/x86/include/asm/msi.h:5, | from ./include/linux/msi.h:23, | from ./include/linux/kvm_host.h:19, | from arch/x86/kernel/../kvm/vmx/vmx.h:5, | from arch/x86/kernel/asm-offsets.c:22: | ./include/linux/irqdomain.h: In function 'irq_domain_alloc_irqs': | ./include/linux/irqdomain.h:514:38: warning: declaration of 'nr_irqs' shadows a global declaration [-Wshadow] | 514 | unsigned int nr_irqs, int node, void *arg) | | ~~~~~~~~~~~~~^~~~~~~ | In file included from ./include/linux/interrupt.h:10, | from ./include/linux/kernel_stat.h:9, | from ./include/linux/cgroup.h:26, | from ./include/linux/memcontrol.h:13, | from ./include/linux/swap.h:9, | from ./include/linux/suspend.h:5, | from arch/x86/kernel/asm-offsets.c:13: | ./include/linux/irqnr.h:8:12: note: shadowed declaration is here | 8 | extern int nr_irqs; | | ^~~~~~~Signed-off-by Vincent Mailhol <[email protected]>--- include/linux/irqdomain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/irqdomain.h +2
-2@@ -511,9 +511,9 @@ extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);extern void irq_domain_deactivate_irq (struct irq_data *irq_data);static inline int irq_domain_alloc_irqs (struct irq_domain *domain, -unsigned int nr_irqs,int node,void *arg) +unsigned int nbr_irqs,int node,void *arg) { -return __irq_domain_alloc_irqs (domain,-1 , nr_irqs, node, arg, false, +return __irq_domain_alloc_irqs (domain,-1 , nbr_irqs, node, arg, false,NULL );Quoted 1 line
}
I really don't think this is worth it. A function has its own namespace, and this warning is on the long list of "this is completely silly". Case in point:
Quoted 4 lines
$ git grep 'unsigned int nr_irqs'| wc -l 207Is anything broken? Not as far as I can tell.
Nothing is broken, my only concern is that this occurs in a header file and thus the warning will pop up in random files which include this header.
| git grep "unsigned int nr_irqs" include/ arch/*/include | wc -l | 17
(and all static inline function which trigger the warning are from linux/irqdomain.h)
Time to time, I check the W=2 output and spam from the headers makes it annoying to triage. I absolutely do not care of shadowing everywhere else outside of the includes directory.
Quoted 3 lines
If there was anything to fix, it is the top-level definition that should be more indicative of its global status. But again, there is nothing broken so far.
This is also feasible, but it will become a tree-wide patch. And I am quite certain that it will be NACKed right away, so I will not try this alternate solution.
Yours sincerely,
Vincent Mailhol
Quoted 79 lines · Vincent MAILHOL
Quoted 60 lines · Marc Zyngier
Quoted 53 lines · Vincent Mailhol
include/linux/irqnr.hdeclares a global variable named `nr_irqs'.The inline function
irq_domain_alloc_irqs()frominclude/linux/irqdomain.halso uses the same name and thus shadow the global declaration. Rename the function argument fromnr_irqs' tonbr_irqs'.This patch silences below -Wshadow warning:
| In file included from ./arch/x86/include/asm/irqdomain.h:5, | from ./arch/x86/include/asm/msi.h:5, | from ./include/linux/msi.h:23, | from ./include/linux/kvm_host.h:19, | from arch/x86/kernel/../kvm/vmx/vmx.h:5, | from arch/x86/kernel/asm-offsets.c:22: | ./include/linux/irqdomain.h: In function 'irq_domain_alloc_irqs': | ./include/linux/irqdomain.h:514:38: warning: declaration of 'nr_irqs' shadows a global declaration [-Wshadow] | 514 | unsigned int nr_irqs, int node, void *arg) | | ~~~~~~~~~~~~~^~~~~~~ | In file included from ./include/linux/interrupt.h:10, | from ./include/linux/kernel_stat.h:9, | from ./include/linux/cgroup.h:26, | from ./include/linux/memcontrol.h:13, | from ./include/linux/swap.h:9, | from ./include/linux/suspend.h:5, | from arch/x86/kernel/asm-offsets.c:13: | ./include/linux/irqnr.h:8:12: note: shadowed declaration is here | 8 | extern int nr_irqs; | | ^~~~~~~Signed-off-by Vincent Mailhol <[email protected]>--- include/linux/irqdomain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/irqdomain.h +2
-2@@ -511,9 +511,9 @@ extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);extern void irq_domain_deactivate_irq (struct irq_data *irq_data);static inline int irq_domain_alloc_irqs (struct irq_domain *domain, -unsigned int nr_irqs,int node,void *arg) +unsigned int nbr_irqs,int node,void *arg) { -return __irq_domain_alloc_irqs (domain,-1 , nr_irqs, node, arg, false, +return __irq_domain_alloc_irqs (domain,-1 , nbr_irqs, node, arg, false,NULL );Quoted 1 line
}
I really don't think this is worth it. A function has its own namespace, and this warning is on the long list of "this is completely silly". Case in point:
Quoted 4 lines
$ git grep 'unsigned int nr_irqs'| wc -l 207Is anything broken? Not as far as I can tell.
Nothing is broken, my only concern is that this occurs in a header file and thus the warning will pop up in random files which include this header.
| git grep "unsigned int nr_irqs" include/ arch/*/include | wc -l | 17(and all static inline function which trigger the warning are from
linux/irqdomain.h)Time to time, I check the W=2 output and spam from the headers makes it annoying to triage. I absolutely do not care of shadowing everywhere else outside of the includes directory.
Quoted 7 lines
Quoted 3 lines
If there was anything to fix, it is the top-level definition that should be more indicative of its global status. But again, there is nothing broken so far.
This is also feasible, but it will become a tree-wide patch. And I am quite certain that it will be NACKed right away, so I will not try this alternate solution.
To add some figures, on a "make allyesconfig" (linux-next branch, x86_64 build, gcc 12), there are in total 36005 -Wshadow and irqdomain.h accounts for 7094 of all these (i.e. this patch suppresses roughly one fifth of all -Wshadow warnings tree wide).
Yours sincerely,
Vincent Mailhol