]> www.infradead.org Git - users/hch/misc.git/commitdiff
vdso: Address variable shadowing in macros
authorPeng Jiang <jiang.peng9@zte.com.cn>
Mon, 24 Mar 2025 11:12:30 +0000 (19:12 +0800)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 10 Apr 2025 09:07:10 +0000 (11:07 +0200)
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

index eee3d2a4dbe4d3dff1e59433dccbb6d39c2d71ff..ff0c06b6513eff61046f9fcf40111c9a8baf176b 100644 (file)
@@ -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 */