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

From: Alexei Starovoitov
Date: Wed Jun 11 2025 - 14:20:43 EST


On Wed, Jun 11, 2025 at 10:57 AM Vlastimil Babka <vbabka@xxxxxxx> wrote:
>
> 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; \

I wouldn't bother messing with the code because of sparse.
Compilers don't warn here.