mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: HONG Yifan <elsk@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>
Cc: kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] checkpatch: externalize function-like type macros
Date: Wed, 02 Dec 2026 08:55:20 -0800	[thread overview]
Message-ID: <fefefe37b48eaf09859a4206f55257e847c7fd20.camel@perches.com> (raw)
In-Reply-To: <20261118193921.683813-1-elsk@google.com>

On Wed, 2026-11-18 at 19:39 +0000, HONG Yifan wrote:
> tools/testing/selftests/kselftest_harness.h defines FIXTURE_DATA() and
> FIXTURE_VARIANT() to expand to struct type specifiers
> ("struct _test_data_##datatype_name" and
> "struct _fixture_variant_##fixture_name").

Acked-by: Joe Perches <joe@perches.com

> 
> Because checkpatch.pl does not recognize these function-like macros in
> $NonptrType or $NonptrTypeWithAttr, annotate_values() parses them as
> function calls and tags a following '*' as a binary multiplication
> operator instead of a pointer declarator.  This triggers false-positive
> errors across kselftests whenever helper functions take pointers to
> fixture data or variants (over 150 sites in tools/testing/selftests/),
> for example on commit d2b82fa39fda ("selftests/mm: add a GUP selftest"):
> 
>   ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
>   #319: FILE: tools/testing/selftests/mm/gup.c:191:
>   +		FIXTURE_DATA(gup_test) *self,
> 
> Following scripts/const_structs.checkpatch in commit bf1fa1dae68e
> ("checkpatch: externalize the structs that should be const"), read
> additional function-like type macro names from a new companion file
> scripts/type_macros.checkpatch into $type_macros (named to mirror
> $const_structs/$conststructsfile and initialized with the built-in
> typeof and __typeof__ keywords) and use $type_macros in $NonptrType and
> $NonptrTypeWithAttr.
> 
> Seed scripts/type_macros.checkpatch with FIXTURE_DATA and
> FIXTURE_VARIANT, and list scripts/*.checkpatch under CHECKPATCH in
> MAINTAINERS.  Valid pointer declarations and casts no longer emit false
> SPACING errors, while malformed pointer placement (such as
> "FIXTURE_DATA(foo)* p" or "(FIXTURE_DATA(foo)*)p") is flagged by
> POINTER_LOCATION.  Keep typeof and __typeof__ built-in as C/GCC
> language operators so $type_macros is never empty and typeof() keeps
> working when scripts/type_macros.checkpatch is missing or empty.
> 
> Signed-off-by: HONG Yifan <elsk@google.com>
> ---
> Changes in v2:
> - Externalize FIXTURE_DATA and FIXTURE_VARIANT into
>   scripts/type_macros.checkpatch instead of hardcoding them in
>   scripts/checkpatch.pl, matching scripts/const_structs.checkpatch from
>   commit bf1fa1dae68e ("checkpatch: externalize the structs that should
>   be const").
> - Add scripts/*.checkpatch under CHECKPATCH in MAINTAINERS.
> - Link to v1: https://lore.kernel.org/r/20261117220522.904290-1-elsk@google.com
> 
>  MAINTAINERS                    | 1 +
>  scripts/checkpatch.pl          | 9 +++++++--
>  scripts/type_macros.checkpatch | 6 ++++++
>  3 files changed, 14 insertions(+), 2 deletions(-)
>  create mode 100644 scripts/type_macros.checkpatch
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index d738990161bd..b0dca8edb154 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6264,6 +6264,7 @@ CHECKPATCH
>  M:	Andy Whitcroft <apw@canonical.com>
>  M:	Joe Perches <joe@perches.com>
>  S:	Maintained
> +F:	scripts/*.checkpatch
>  F:	scripts/checkpatch.pl
> 
>  CHECKPATCH DOCUMENTATION
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b8b64f720191..7500e1cf447f 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -71,6 +71,7 @@ my $codespell = 0;
>  my $codespellfile = "/usr/share/codespell/dictionary.txt";
>  my $user_codespellfile = "";
>  my $conststructsfile = "$D/const_structs.checkpatch";
> +my $typemacrosfile = "$D/type_macros.checkpatch";
>  my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
>  my $typedefsfile;
>  my $color = "auto";
> @@ -1053,6 +1054,10 @@ if (defined($typedefsfile)) {
>  	$typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs);
>  }
> 
> +my $type_macros = "typeof|__typeof__";
> +read_words(\$type_macros, $typemacrosfile)
> +    or warn "No additional type macros will be considered - file '$typemacrosfile': $!\n";
> +
>  sub build_types {
>  	my $mods = "(?x:  \n" . join("|\n  ", (@modifierList, @modifierListFile)) . "\n)";
>  	my $all = "(?x:  \n" . join("|\n  ", (@typeList, @typeListFile)) . "\n)";
> @@ -1066,7 +1071,7 @@ sub build_types {
>  	$NonptrType	= qr{
>  			(?:$Modifier\s+|const\s+)*
>  			(?:
> -				(?:typeof|__typeof__)\s*\([^\)]*\)|
> +				(?:$type_macros)\s*\([^\)]*\)|
>  				(?:$typeTypedefs\b)|
>  				(?:${all}\b)
>  			)
> @@ -1082,7 +1087,7 @@ sub build_types {
>  	$NonptrTypeWithAttr	= qr{
>  			(?:$Modifier\s+|const\s+)*
>  			(?:
> -				(?:typeof|__typeof__)\s*\([^\)]*\)|
> +				(?:$type_macros)\s*\([^\)]*\)|
>  				(?:$typeTypedefs\b)|
>  				(?:${allWithAttr}\b)
>  			)
> diff --git a/scripts/type_macros.checkpatch b/scripts/type_macros.checkpatch
> new file mode 100644
> index 000000000000..c910a09e2ebc
> --- /dev/null
> +++ b/scripts/type_macros.checkpatch
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Function-like macros that expand to type specifiers (for example,
> +# struct types) and take parenthesized arguments.
> +FIXTURE_DATA
> +FIXTURE_VARIANT
> --
> 2.56.1.708.g77570a6a1d-goog

      parent reply	other threads:[~2026-12-02 16:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:39 HONG Yifan
2026-11-18 20:17 ` Joe Perches
2026-11-30 21:07   ` Hong, Yifan
2026-12-01 18:18     ` Joe Perches
2026-12-02 16:55 ` Joe Perches [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=fefefe37b48eaf09859a4206f55257e847c7fd20.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=elsk@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    /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®