mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: apw@canonical.com, joe@perches.com, akpm@linux-foundation.org,
	 dwaipayanray1@gmail.com, linux-kernel@vger.kernel.org,
	 kernel-team@android.com, mkl@pengutronix.de
Subject: Re: [PATCH v2] checkpatch: Add context-analysis attributes
Date: Mon, 16 Nov 2026 22:31:20 +0100	[thread overview]
Message-ID: <CANpmjNP5ShLAg8NcAc3aj_VBDBnjSmObRdZydnDxg9bDscqcAg@mail.gmail.com> (raw)
In-Reply-To: <20261116172836.2254432-1-vdonnefort@google.com>

On Mon, 16 Nov 2026 at 18:28, 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 prototypes). Add them to the known attributes list with
> support for a single nested set of parentheses.
>
> Handle context-analysis attributes with parentheses like __attribute__
> in annotate_values() so unary '&' in their arguments is not mistaken for
> binary bitwise AND.
>
> Cc: Marco Elver <elver@google.com>
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

Acked-by: Marco Elver <elver@google.com>

> ---
>  scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++++-----
>  1 file changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b8b64f720191..5ca2a1fc2607 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -527,6 +527,32 @@ our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
>  our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
>  our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
>
> +# Match (...) attribute arguments, allowing one level of nested parens
> +# (e.g. __guarded_by(__bitlock(3, &bits))).
> +our $AttrParens = qr{\s*\((?:[^()]++|\([^()]*+\))*+\)};
> +our $ContextAnalysisWithArgs = qr{
> +                       __guarded_by|
> +                       __pt_guarded_by|
> +                       __must_hold|
> +                       __must_hold_shared|
> +                       __must_not_hold|
> +                       __acquires|
> +                       __acquires_shared|
> +                       __cond_acquires|
> +                       __cond_acquires_shared|
> +                       __releases|
> +                       __releases_shared|
> +                       __cond_releases|
> +                       __context_unsafe
> +               }x;
> +our $ContextAnalysis = qr{
> +                       (?:$ContextAnalysisWithArgs)$AttrParens|
> +                       __rcu_guarded\b|
> +                       __no_context_analysis\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
>  our $Attribute = qr{
> @@ -551,6 +577,7 @@ our $Attribute      = qr{
>                         __ro_after_init|
>                         __kprobes|
>                         $InitAttribute|
> +                       $ContextAnalysis|
>                         __aligned\s*\(.*\)|
>                         ____cacheline_aligned|
>                         ____cacheline_aligned_in_smp|
> @@ -2141,6 +2168,11 @@ sub annotate_values {
>                         push(@av_paren_type, $type);
>                         $type = 'c';
>
> +               } elsif ($cur =~ /^(__attribute__|$ContextAnalysisWithArgs)\b\s*\(?/o) {
> +                       print "ATTR($1)\n" if ($dbg_values > 1);
> +                       $av_pending = $type;
> +                       $type = 'N';
> +
>                 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
>                         print "DECLARE($1)\n" if ($dbg_values > 1);
>                         $type = 'T';
> @@ -2193,11 +2225,6 @@ sub annotate_values {
>                 } elsif ($cur =~ /^(\\\n)/o) {
>                         print "PRECONT($1)\n" if ($dbg_values > 1);
>
> -               } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
> -                       print "ATTR($1)\n" if ($dbg_values > 1);
> -                       $av_pending = $type;
> -                       $type = 'N';
> -
>                 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
>                         print "SIZEOF($1)\n" if ($dbg_values > 1);
>                         if (defined $2) {
>
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> --
> 2.56.1.703.gf848ed807c-goog
>

      reply	other threads:[~2026-11-16 21:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:28 Vincent Donnefort
2026-11-16 21:31 ` Marco Elver [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANpmjNP5ShLAg8NcAc3aj_VBDBnjSmObRdZydnDxg9bDscqcAg@mail.gmail.com \
    --to=elver@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=vdonnefort@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®