Re: locking/local_lock, mm: sparse warnings about shadowed variable
From: Charlemagne Lasse
Date: Thu Jun 12 2025 - 03:03:48 EST
Am Mi., 11. Juni 2025 um 20:20 Uhr schrieb Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx>:
> I wouldn't bother messing with the code because of sparse.
> Compilers don't warn here.
Actually, they do:
$ make W=2 mm/mlock.o
[...]
In file included from ./include/linux/preempt.h:11,
from ./include/linux/spinlock.h:56,
from ./include/linux/wait.h:9,
from ./include/linux/wait_bit.h:8,
from ./include/linux/fs.h:7,
from ./include/linux/mman.h:5,
from mm/mlock.c:10:
./include/linux/local_lock.h: In function
‘class_local_lock_irqsave_constructor’:
./include/linux/local_lock_internal.h:100:31: warning: declaration of
‘l’ shadows a parameter [-Wshadow]
100 | local_lock_t *l; \
| ^
./include/linux/cleanup.h:394:9: note: in definition of macro
‘__DEFINE_LOCK_GUARD_1’
394 | _lock; \
| ^~~~~
./include/linux/local_lock.h:88:1: note: in expansion of macro
‘DEFINE_LOCK_GUARD_1’
88 | DEFINE_LOCK_GUARD_1(local_lock_irqsave, local_lock_t __percpu,
| ^~~~~~~~~~~~~~~~~~~
./include/linux/local_lock_internal.h:128:17: note: in expansion of
macro ‘__local_lock_acquire’
128 | __local_lock_acquire(lock); \
| ^~~~~~~~~~~~~~~~~~~~
./include/linux/local_lock.h:31:9: note: in expansion of macro
‘__local_lock_irqsave’
31 | __local_lock_irqsave(lock, flags)
| ^~~~~~~~~~~~~~~~~~~~
./include/linux/local_lock.h:89:21: note: in expansion of macro
‘local_lock_irqsave’
89 | local_lock_irqsave(_T->lock, _T->flags),
| ^~~~~~~~~~~~~~~~~~
./include/linux/cleanup.h:391:68: note: shadowed declaration is here
391 | static inline class_##_name##_t class_##_name##_constructor(_type *l) \
./include/linux/cleanup.h:410:1: note: in expansion of macro
‘__DEFINE_LOCK_GUARD_1’
410 | __DEFINE_LOCK_GUARD_1(_name, _type, _lock)
| ^~~~~~~~~~~~~~~~~~~~~
./include/linux/local_lock.h:88:1: note: in expansion of macro
‘DEFINE_LOCK_GUARD_1’
88 | DEFINE_LOCK_GUARD_1
$ gcc --version
gcc (Debian 14.2.0-19) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.