mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] random: vDSO: Fix shadow declarations
@ 2025-03-24 11:12 shao.mingyin
  2025-04-10  9:12 ` [tip: timers/urgent] vdso: Address variable shadowing in macros tip-bot2 for Peng Jiang
  0 siblings, 1 reply; 2+ messages in thread
From: shao.mingyin @ 2025-03-24 11:12 UTC (permalink / raw)
  To: luto
  Cc: tglx, vincenzo.frascino, linux-kernel, yang.yang29, xu.xin16,
	ye.xingchen, jiang.peng9

From: Peng Jiang <jiang.peng9@zte.com.cn>

Compiling the kernel with gcc12.3 W=2 produces a warning:
In file included from linux-next/lib/vdso/getrandom.c:10,
                 from <command-line>:
linux-next/lib/vdso/getrandom.c: In function 'memcpy_and_zero_src':
./include/vdso/unaligned.h:6:44:
warning: declaration of '__pptr' shadows a previous local [-Wshadow]
  6 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);
    |                                    ^~~~~~
./include/vdso/unaligned.h:12:22:
note: in definition of macro '__put_unaligned_t'
 12 | __pptr->x = (val);
    |               ^~~
linux-next/lib/vdso/getrandom.c:25:41:
note: in expansion of macro '__get_unaligned_t'
 25 | __put_unaligned_t(type, __get_unaligned_t(type, src), dst);
    |                                         ^~~~~~~~~~~~~~~~~
linux-next/lib/vdso/getrandom.c:37:25:
note: in expansion of macro 'MEMCPY_AND_ZERO_SRC'
 37 | MEMCPY_AND_ZERO_SRC(u64, dst, src, len);

To reproduce the issue before applying the patch:
make defconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-
make vmlinux ARCH=arm64 CROSS_COMPILE=aarch64-linux- W=2

The existing implementation of the __get_unaligned_t and __put_unaligned_t
macros in include/vdso/unaligned.h uses a local variable named '__pptr'
which can lead to variable shadowing when these macros are used in
the same scope. This results in a -Wshadow warning during compilation.

To address this issue, we have renamed the local variables within
the macros to ensure uniqueness:
- In __get_unaligned_t, '__pptr' has been renamed to '__get_pptr'.
- In __put_unaligned_t, '__pptr' has been renamed to '__put_pptr'.

These changes prevent variable shadowing and eliminate the
-Wshadow warning, improving code readability and maintainability.

Signed-off-by: Peng Jiang <jiang.peng9@zte.com.cn>
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
 include/vdso/unaligned.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
index eee3d2a4dbe4..ff0c06b6513e 100644
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -2,14 +2,14 @@
 #ifndef __VDSO_UNALIGNED_H
 #define __VDSO_UNALIGNED_H

-#define __get_unaligned_t(type, ptr) ({						\
-	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
-	__pptr->x;								\
+#define __get_unaligned_t(type, ptr) ({							\
+	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
+	__get_pptr->x;									\
 })

-#define __put_unaligned_t(type, val, ptr) do {					\
-	struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);		\
-	__pptr->x = (val);							\
+#define __put_unaligned_t(type, val, ptr) do {						\
+	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
+	__put_pptr->x = (val);								\
 } while (0)

 #endif /* __VDSO_UNALIGNED_H */
-- 
2.25.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip: timers/urgent] vdso: Address variable shadowing in macros
  2025-03-24 11:12 [PATCH] random: vDSO: Fix shadow declarations shao.mingyin
@ 2025-04-10  9:12 ` tip-bot2 for Peng Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Peng Jiang @ 2025-04-10  9:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Peng Jiang, Shao Mingyin, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     acea9943271b62905033f2f8ca571cdd52d6ea7b
Gitweb:        https://git.kernel.org/tip/acea9943271b62905033f2f8ca571cdd52d6ea7b
Author:        Peng Jiang <jiang.peng9@zte.com.cn>
AuthorDate:    Mon, 24 Mar 2025 19:12:30 +08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 10 Apr 2025 11:07:10 +02:00

vdso: Address variable shadowing in macros

Compiling the kernel with gcc12.3 W=2 results in shadowing warnings:

warning: declaration of '__pptr' shadows a previous local [-Wshadow]
  const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);

note: in definition of macro '__put_unaligned_t'
  __pptr->x = (val);

note: in expansion of macro '__get_unaligned_t'
  __put_unaligned_t(type, __get_unaligned_t(type, src), dst);

__get_unaligned_t() and __put_unaligned_t() use a local variable named
'__pptr', which can lead to variable shadowing when these macros are used in
the same scope. This results in a -Wshadow warning during compilation.

To address this issue, rename the local variables within the macros to
ensure uniqueness.

Signed-off-by: Peng Jiang <jiang.peng9@zte.com.cn>
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250324191230477zpGtgIRSH4mEHdtxGtgx9@zte.com.cn
---
 include/vdso/unaligned.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
index eee3d2a..ff0c06b 100644
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -2,14 +2,14 @@
 #ifndef __VDSO_UNALIGNED_H
 #define __VDSO_UNALIGNED_H
 
-#define __get_unaligned_t(type, ptr) ({						\
-	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
-	__pptr->x;								\
+#define __get_unaligned_t(type, ptr) ({							\
+	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
+	__get_pptr->x;									\
 })
 
-#define __put_unaligned_t(type, val, ptr) do {					\
-	struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);		\
-	__pptr->x = (val);							\
+#define __put_unaligned_t(type, val, ptr) do {						\
+	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
+	__put_pptr->x = (val);								\
 } while (0)
 
 #endif /* __VDSO_UNALIGNED_H */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-10  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-24 11:12 [PATCH] random: vDSO: Fix shadow declarations shao.mingyin
2025-04-10  9:12 ` [tip: timers/urgent] vdso: Address variable shadowing in macros tip-bot2 for Peng Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®