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

From: Joe Perches

Date: Sat Nov 14 2026 - 09:26:40 EST


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.