Re: [PATCH] locking/local_lock: fix shadowing in __local_lock_acquire()
From: Alexei Starovoitov
Date: Tue Sep 23 2025 - 15:38:38 EST
On Tue, Sep 23, 2025 at 7:02 AM Vincent Mailhol <mailhol@xxxxxxxxxx> wrote:
>
> The __local_lock_acquire() macro uses a local variable named 'l'. This
> being a common name, there is a risk of shadowing other variables.
>
> For example, it is currently shadowing the parameter 'l' of the:
>
> class_##_name##_t class_##_name##_constructor(_type *l)
>
> function factory from linux/cleanup.h.
>
> Both sparse (with default options) and GCC (with W=2 option) warn
> about this shadowing.
>
> This is a bening warning, but because the issue appears in a header,
> it is spamming whoever is using it. So better to fix to remove some
> noise.
>
> Rename the variable from 'l' to '__lock' (with two underscore prefixes
> as suggested in the Linux kernel coding style [1]) in order to prevent
> the name collision.
lockdep has __lock as a local variable.
So the patch won't really fix the paranoid warning.
I think it's better to fix sparse to silence this warn.