2020-10-26 20:46:52

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] asm-generic: percpu: avoid Wshadow warning

From: Arnd Bergmann <[email protected]>

Nesting macros that use the same local variable names causes
warnings when building with "make W=2":

include/asm-generic/percpu.h:117:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]
include/asm-generic/percpu.h:126:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]

These are fairly harmless, but since the warning comes from
a global header, the warning happens every time the headers
are included, which is fairly annoying.

Rename the variables to avoid shadowing and shut up the warning.

Signed-off-by: Arnd Bergmann <[email protected]>
---
include/asm-generic/percpu.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index 35e4a53b83e6..6432a7fade91 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -114,21 +114,21 @@ do { \

#define __this_cpu_generic_read_nopreempt(pcp) \
({ \
- typeof(pcp) __ret; \
+ typeof(pcp) ___ret; \
preempt_disable_notrace(); \
- __ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \
+ ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \
preempt_enable_notrace(); \
- __ret; \
+ ___ret; \
})

#define __this_cpu_generic_read_noirq(pcp) \
({ \
- typeof(pcp) __ret; \
- unsigned long __flags; \
- raw_local_irq_save(__flags); \
- __ret = raw_cpu_generic_read(pcp); \
- raw_local_irq_restore(__flags); \
- __ret; \
+ typeof(pcp) ___ret; \
+ unsigned long ___flags; \
+ raw_local_irq_save(___flags); \
+ ___ret = raw_cpu_generic_read(pcp); \
+ raw_local_irq_restore(___flags); \
+ ___ret; \
})

#define this_cpu_generic_read(pcp) \
--
2.27.0


2020-10-27 00:03:57

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] asm-generic: percpu: avoid Wshadow warning

On Mon, Oct 26, 2020 at 04:53:48PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
>
> Nesting macros that use the same local variable names causes
> warnings when building with "make W=2":
>
> include/asm-generic/percpu.h:117:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]
> include/asm-generic/percpu.h:126:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]
>
> These are fairly harmless, but since the warning comes from
> a global header, the warning happens every time the headers
> are included, which is fairly annoying.
>
> Rename the variables to avoid shadowing and shut up the warning.

Looks good to me. Fell free to add my:

Reviewed-by: Luc Van Oostenryck <[email protected]>

2020-10-27 00:21:36

by Dennis Zhou

[permalink] [raw]
Subject: Re: [PATCH] asm-generic: percpu: avoid Wshadow warning

Hello,

On Mon, Oct 26, 2020 at 04:53:48PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
>
> Nesting macros that use the same local variable names causes
> warnings when building with "make W=2":
>
> include/asm-generic/percpu.h:117:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]
> include/asm-generic/percpu.h:126:14: warning: declaration of '__ret' shadows a previous local [-Wshadow]
>
> These are fairly harmless, but since the warning comes from
> a global header, the warning happens every time the headers
> are included, which is fairly annoying.
>
> Rename the variables to avoid shadowing and shut up the warning.
>
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> include/asm-generic/percpu.h | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
> index 35e4a53b83e6..6432a7fade91 100644
> --- a/include/asm-generic/percpu.h
> +++ b/include/asm-generic/percpu.h
> @@ -114,21 +114,21 @@ do { \
>
> #define __this_cpu_generic_read_nopreempt(pcp) \
> ({ \
> - typeof(pcp) __ret; \
> + typeof(pcp) ___ret; \
> preempt_disable_notrace(); \
> - __ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \
> + ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \
> preempt_enable_notrace(); \
> - __ret; \
> + ___ret; \
> })
>
> #define __this_cpu_generic_read_noirq(pcp) \
> ({ \
> - typeof(pcp) __ret; \
> - unsigned long __flags; \
> - raw_local_irq_save(__flags); \
> - __ret = raw_cpu_generic_read(pcp); \
> - raw_local_irq_restore(__flags); \
> - __ret; \
> + typeof(pcp) ___ret; \
> + unsigned long ___flags; \
> + raw_local_irq_save(___flags); \
> + ___ret = raw_cpu_generic_read(pcp); \
> + raw_local_irq_restore(___flags); \
> + ___ret; \
> })
>
> #define this_cpu_generic_read(pcp) \
> --
> 2.27.0
>

I've applied this to percpu#for-5.10-fixes.

Thanks,
Dennis