* [PATCH v1] checkpatch: Add context-analysis attributes
@ 2026-11-12 15:12 Vincent Donnefort
2026-11-12 15:23 ` Marco Elver
2026-11-13 3:32 ` Joe Perches
0 siblings, 2 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-11-12 15:12 UTC (permalink / raw)
To: apw, joe, akpm
Cc: dwaipayanray1, elver, linux-kernel, vdonnefort, kernel-team
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@google.com>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] checkpatch: Add context-analysis attributes
2026-11-12 15:12 [PATCH v1] checkpatch: Add context-analysis attributes Vincent Donnefort
@ 2026-11-12 15:23 ` Marco Elver
2026-11-13 3:32 ` Joe Perches
1 sibling, 0 replies; 6+ messages in thread
From: Marco Elver @ 2026-11-12 15:23 UTC (permalink / raw)
To: Vincent Donnefort
Cc: apw, joe, akpm, dwaipayanray1, linux-kernel, kernel-team
On Thu, 12 Nov 2026 at 16:12, Vincent Donnefort <vdonnefort@google.com> 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@google.com>
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Acked-by: <elver@google.com>
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
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] checkpatch: Add context-analysis attributes
2026-11-12 15:12 [PATCH v1] checkpatch: Add context-analysis attributes Vincent Donnefort
2026-11-12 15:23 ` Marco Elver
@ 2026-11-13 3:32 ` Joe Perches
2026-11-14 13:21 ` Vincent Donnefort
1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2026-11-13 3:32 UTC (permalink / raw)
To: Vincent Donnefort, apw, akpm; +Cc: elver, linux-kernel, kernel-team
On Thu, 2026-11-12 at 15:12 +0000, Vincent Donnefort 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.
Nak.
> diff --git 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{
Are all of these from include/linux/compiler-context-analysis.h ?
> + __guarded_by\b|
__guarded_by takes an argument so it should be
__guarded_by\s*\(.*\)
like the __aligned use below in $Attribute
> + __pt_guarded_by\b|
And all the rest of these entries that take arguments need to add
that same '\s*\(.*\)'
and it'll be fragile besides, multiline uses likely won't work,
any use that has another internal () pair won't work, etc...
> + __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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] checkpatch: Add context-analysis attributes
2026-11-13 3:32 ` Joe Perches
@ 2026-11-14 13:21 ` Vincent Donnefort
2026-11-14 14:26 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Vincent Donnefort @ 2026-11-14 13:21 UTC (permalink / raw)
To: Joe Perches; +Cc: apw, akpm, elver, linux-kernel, kernel-team
On Thu, Nov 12, 2026 at 07:32:14PM -0800, Joe Perches wrote:
> On Thu, 2026-11-12 at 15:12 +0000, Vincent Donnefort 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.
>
> Nak.
>
> > diff --git 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{
>
> Are all of these from include/linux/compiler-context-analysis.h ?
Correct, except __rcu_guarded, which I can drop.
>
> > + __guarded_by\b|
>
> __guarded_by takes an argument so it should be
>
> __guarded_by\s*\(.*\)
>
> like the __aligned use below in $Attribute
>
> > + __pt_guarded_by\b|
>
> And all the rest of these entries that take arguments need to add
> that same '\s*\(.*\)'
>
> and it'll be fragile besides, multiline uses likely won't work,
> any use that has another internal () pair won't work, etc...
How about matching one internal () pair?
__guarded_by\s*\(
(?:
[^()]++ |
\([^()]*+\)
)*+
\)
This would at least cover all existing declarations.
--
Vincent
>
> > + __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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] checkpatch: Add context-analysis attributes
2026-11-14 13:21 ` Vincent Donnefort
@ 2026-11-14 14:26 ` Joe Perches
2026-11-14 14:57 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2026-11-14 14:26 UTC (permalink / raw)
To: Vincent Donnefort; +Cc: apw, akpm, elver, linux-kernel, kernel-team
On Sat, 2026-11-14 at 13:21 +0000, Vincent Donnefort wrote:
> On Thu, Nov 12, 2026 at 07:32:14PM -0800, Joe Perches wrote:
> > On Thu, 2026-11-12 at 15:12 +0000, Vincent Donnefort 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.
> >
> > Nak.
> >
> > > diff --git 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{
> >
> > Are all of these from include/linux/compiler-context-analysis.h ?
>
> Correct, except __rcu_guarded, which I can drop.
Not necessary really, it uses __guarded_by internally.
> >
> > > + __guarded_by\b|
> >
> > __guarded_by takes an argument so it should be
> >
> > __guarded_by\s*\(.*\)
> >
> > like the __aligned use below in $Attribute
> >
> > > + __pt_guarded_by\b|
> >
> > And all the rest of these entries that take arguments need to add
> > that same '\s*\(.*\)'
> >
> > and it'll be fragile besides, multiline uses likely won't work,
> > any use that has another internal () pair won't work, etc...;
>
> How about matching one internal () pair?
>
> __guarded_by\s*\(
> (?:
> [^()]++ |
> \([^()]*+\)
> )*+
> \)
Sure.
Please add and use another variable so it's not repeated everywhere.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1] checkpatch: Add context-analysis attributes
2026-11-14 14:26 ` Joe Perches
@ 2026-11-14 14:57 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2026-11-14 14:57 UTC (permalink / raw)
To: Vincent Donnefort; +Cc: apw, akpm, elver, linux-kernel, kernel-team
On Sat, 2026-11-14 at 06:26 -0800, Joe Perches wrote:
> > How about matching one internal () pair?
> >
> > __guarded_by\s*\(
> > (?:
> > [^()]++ |
> > \([^()]*+\)
> > )*+
> > \)
>
> Sure.
> Please add and use another variable so it's not repeated everywhere.
Reading a bit about balanced parentheses in perl '(?R)'
non capturing recursion works since 5.10.0
Maybe instead use
/\((?:[^()]++|(?R))*\)/
and I should probably rework all of checkpatch's uses of
$balanced_parens to avoid all those weird capture group uses
as it was originally written for perl 5.8 (thanks akpm)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-14 14:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 15:12 [PATCH v1] checkpatch: Add context-analysis attributes Vincent Donnefort
2026-11-12 15:23 ` Marco Elver
2026-11-13 3:32 ` Joe Perches
2026-11-14 13:21 ` Vincent Donnefort
2026-11-14 14:26 ` Joe Perches
2026-11-14 14:57 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®