Re: locking/local_lock, mm: sparse warnings about shadowed variable

From: Vlastimil Babka
Date: Wed Jun 11 2025 - 13:57:58 EST


On 6/11/25 19:37, Charlemagne Lasse wrote:
> HI,
>
> when I run `make C=2 mm/mlock.o CHECK="sparse -Wshadow"`, I get a lot of
>
> ./include/linux/local_lock.h:88:1: warning: symbol 'l' shadows an earlier one
> ./include/linux/local_lock.h:88:1: originally declared here
>
> after commit
>
> 51339d99c0131bc0d16d378e9b05bc498d2967e2 is the first bad commit
> commit 51339d99c0131bc0d16d378e9b05bc498d2967e2
> Author: Alexei Starovoitov <ast@xxxxxxxxxx>
> Date: 2025-04-02 19:55:14 -0700
>
> locking/local_lock, mm: replace localtry_ helpers with local_trylock_t type

Looks like __DEFINE_LOCK_GUARD_1() has "_type *l" and __local_lock_acquire()
has "local_lock_t *l;". It can be fixed e.g. like this, although it's
harmless? The _release() part is not necessary, just for symmetry.

diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h
index 8d5ac16a9b17..075338f270d0 100644
--- a/include/linux/local_lock_internal.h
+++ b/include/linux/local_lock_internal.h
@@ -97,17 +97,17 @@ do { \
#define __local_lock_acquire(lock) \
do { \
local_trylock_t *tl; \
- local_lock_t *l; \
+ local_lock_t *ll; \
\
- l = (local_lock_t *)this_cpu_ptr(lock); \
- tl = (local_trylock_t *)l; \
+ ll = (local_lock_t *)this_cpu_ptr(lock); \
+ tl = (local_trylock_t *)ll; \
_Generic((lock), \
__percpu local_trylock_t *: ({ \
lockdep_assert(tl->acquired == 0); \
WRITE_ONCE(tl->acquired, 1); \
}), \
__percpu local_lock_t *: (void)0); \
- local_lock_acquire(l); \
+ local_lock_acquire(ll); \
} while (0)

#define __local_lock(lock) \
@@ -165,11 +165,11 @@ do { \
#define __local_lock_release(lock) \
do { \
local_trylock_t *tl; \
- local_lock_t *l; \
+ local_lock_t *ll; \
\
- l = (local_lock_t *)this_cpu_ptr(lock); \
- tl = (local_trylock_t *)l; \
- local_lock_release(l); \
+ ll = (local_lock_t *)this_cpu_ptr(lock); \
+ tl = (local_trylock_t *)ll; \
+ local_lock_release(ll); \
_Generic((lock), \
__percpu local_trylock_t *: ({ \
lockdep_assert(tl->acquired == 1); \