Re: [PATCH v1] checkpatch: Add context-analysis attributes

From: Marco Elver

Date: Thu Nov 12 2026 - 11:45:59 EST


On Thu, 12 Nov 2026 at 16:12, Vincent Donnefort <vdonnefort@xxxxxxxxxx> wrote:
>
> Checkpatch doesn't know about the context analysis attributes and
> misparses annotated declarations (e.g. mistaking __guarded_by() fields
> for extern prototype). Add them to the known attributes list.
>
> Cc: Marco Elver <elver@xxxxxxxxxx>
> Signed-off-by: Vincent Donnefort <vdonnefort@xxxxxxxxxx>

Acked-by: <elver@xxxxxxxxxx>

Thanks!

> ---
> scripts/checkpatch.pl | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b8b64f720191..5210b4ed25ec 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -526,6 +526,25 @@ our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
> our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
> our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
> our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
> +our $ContextAnalysis = qr{
> + __guarded_by\b|
> + __pt_guarded_by\b|
> + __rcu_guarded\b|
> + __must_hold\b|
> + __must_hold_shared\b|
> + __must_not_hold\b|
> + __acquires\b|
> + __acquires_shared\b|
> + __cond_acquires\b|
> + __cond_acquires_shared\b|
> + __releases\b|
> + __releases_shared\b|
> + __cond_releases\b|
> + __no_context_analysis\b|
> + __context_unsafe\b|
> + __acquires_ret\b|
> + __acquires_shared_ret\b
> + }x;
>
> # Notes to $Attribute:
> # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
> @@ -551,6 +570,7 @@ our $Attribute = qr{
> __ro_after_init|
> __kprobes|
> $InitAttribute|
> + $ContextAnalysis|
> __aligned\s*\(.*\)|
> ____cacheline_aligned|
> ____cacheline_aligned_in_smp|
>
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> --
> 2.56.0.567.gdb80ae8cd5-goog
>