Re: [PATCH v5 3/4] cleanup: Annotate guard constructors with nonnull
From: Dan Carpenter
Date: Fri Jun 05 2026 - 01:55:16 EST
On Tue, Jun 02, 2026 at 07:12:52AM +0000, Dmitry Ilvokhin wrote:
> Add __nonnull_args() to unconditional guard constructors so the compiler
> warns when NULL is statically known to be passed:
>
> - DEFINE_GUARD(): re-declare the constructor with __nonnull_args().
> - __DEFINE_LOCK_GUARD_1(): annotate the constructor directly.
>
> DEFINE_LOCK_GUARD_0() needs no annotation: its constructor takes no
> pointer arguments (.lock is hardcoded to (void *)1).
>
> Define the __nonnull_args() macro in compiler_attributes.h, following
> the existing convention for attribute wrappers. Deliberately not named
> '__nonnull', to avoid clashing with glibc's __nonnull() when kernel and
> userspace headers are combined (User Mode Linux for example).
>
> Signed-off-by: Dmitry Ilvokhin <d@xxxxxxxxxxxx>
> ---
> Miguel, I dropped your Acked-by due to the rename. Went with
> __nonnull_args() (over __knonnull()). Happy to restore your tag if that
> spelling works for you.
>
Sparse doesn't like an empty __nonnull_args() at all.
./include/linux/spinlock.h:608:1: error: an expression is expected before ')'
./include/linux/spinlock.h:619:1: error: an expression is expected before ')'
./include/linux/spinlock.h:631:1: error: an expression is expected before ')'
Shouldn't we specify the arguments which are non-NULL?
__nonnull_args(1)?
regards,
dan carpenter