All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: externalize function-like type macros
@ 2026-11-18 19:39 HONG Yifan
  2026-11-18 20:17 ` Joe Perches
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: HONG Yifan @ 2026-11-18 19:39 UTC (permalink / raw)
  To: Andrew Morton, Andy Whitcroft, Joe Perches
  Cc: HONG Yifan, kernel-team, linux-kernel

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").

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] checkpatch: externalize function-like type macros
  2026-11-18 19:39 [PATCH v2] checkpatch: externalize function-like type macros HONG Yifan
@ 2026-11-18 20:17 ` Joe Perches
  2026-11-30 21:07   ` Hong, Yifan
  2026-12-02 16:55 ` Joe Perches
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2026-11-18 20:17 UTC (permalink / raw)
  To: HONG Yifan; +Cc: Andrew Morton, Andy Whitcroft, kernel-team, linux-kernel

On 2026-11-18 11:39, HONG Yifan wrote:

> 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.

Yes like this.

I'll test it before i ack it tomorrow.

Thanks,  Joe

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] checkpatch: externalize function-like type macros
  2026-11-18 20:17 ` Joe Perches
@ 2026-11-30 21:07   ` Hong, Yifan
  2026-12-01 18:18     ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Hong, Yifan @ 2026-11-30 21:07 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andrew Morton, Andy Whitcroft, kernel-team, linux-kernel

On Wed, Nov 18, 2026 at 12:17 PM Joe Perches <joe@perches.com> wrote:
>
> On 2026-11-18 11:39, HONG Yifan wrote:
>
> > 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.
>
> Yes like this.
>
> I'll test it before i ack it tomorrow.
>
> Thanks,  Joe

Hi Joe, just a gentle ping in case this falls off from your list. Did
you have a chance to try out the patch? Thanks for your time!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] checkpatch: externalize function-like type macros
  2026-11-30 21:07   ` Hong, Yifan
@ 2026-12-01 18:18     ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2026-12-01 18:18 UTC (permalink / raw)
  To: Hong, Yifan; +Cc: Andrew Morton, Andy Whitcroft, kernel-team, LKML

On Mon, 2026-11-30 at 13:07 -0800, Hong, Yifan wrote:
> On Wed, Nov 18, 2026 at 12:17 PM Joe Perches <joe@perches.com> wrote:
> > 
> > On 2026-11-18 11:39, HONG Yifan wrote:
> > 
> > > 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.
> > 
> > Yes like this.
> > 
> > I'll test it before i ack it tomorrow.
> > 
> > Thanks,  Joe
> 
> Hi Joe, just a gentle ping in case this falls off from your list. Did
> you have a chance to try out the patch? Thanks for your time!

Sorry, haven't had much time.  It looks exactly right and fine though.
I'll try later this evening.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] checkpatch: externalize function-like type macros
  2026-11-18 19:39 [PATCH v2] checkpatch: externalize function-like type macros HONG Yifan
  2026-11-18 20:17 ` Joe Perches
@ 2026-12-02 16:55 ` Joe Perches
  2026-12-02 18:45 ` + checkpatch-externalize-function-like-type-macros.patch added to mm-nonmm-unstable branch Andrew Morton
  2026-12-02 18:47 ` Andrew Morton
  3 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2026-12-02 16:55 UTC (permalink / raw)
  To: HONG Yifan, Andrew Morton, Andy Whitcroft; +Cc: kernel-team, linux-kernel

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* + checkpatch-externalize-function-like-type-macros.patch added to mm-nonmm-unstable branch
  2026-11-18 19:39 [PATCH v2] checkpatch: externalize function-like type macros HONG Yifan
  2026-11-18 20:17 ` Joe Perches
  2026-12-02 16:55 ` Joe Perches
@ 2026-12-02 18:45 ` Andrew Morton
  2026-12-02 18:47 ` Andrew Morton
  3 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2026-12-02 18:45 UTC (permalink / raw)
  To: mm-commits, joe, apw, elsk, akpm


The patch titled
     Subject: checkpatch: externalize function-like type macros
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     checkpatch-externalize-function-like-type-macros.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/checkpatch-externalize-function-like-type-macros.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: HONG Yifan <elsk@google.com>
Subject: checkpatch: externalize function-like type macros
Date: Wed, 18 Nov 2026 19:39:19 +0000

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").

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.

Link: https://patch.msgid.link/20261118193921.683813-1-elsk@google.com
Signed-off-by: HONG Yifan <elsk@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Joe Perches <joe@perches.com
Cc: Andy Whitcroft <apw@canonical.com>

 MAINTAINERS                    |    1 +
 scripts/checkpatch.pl          |    9 +++++++--
 scripts/type_macros.checkpatch |    6 ++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

--- a/MAINTAINERS~checkpatch-externalize-function-like-type-macros
+++ a/MAINTAINERS
@@ -6265,6 +6265,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
--- a/scripts/checkpatch.pl~checkpatch-externalize-function-like-type-macros
+++ a/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 a/scripts/type_macros.checkpatch
new file mode 100644
--- /dev/null
+++ a/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
_

Patches currently in -mm which might be from elsk@google.com are

checkpatch-externalize-function-like-type-macros.patch


^ permalink raw reply	[flat|nested] 7+ messages in thread

* + checkpatch-externalize-function-like-type-macros.patch added to mm-nonmm-unstable branch
  2026-11-18 19:39 [PATCH v2] checkpatch: externalize function-like type macros HONG Yifan
                   ` (2 preceding siblings ...)
  2026-12-02 18:45 ` + checkpatch-externalize-function-like-type-macros.patch added to mm-nonmm-unstable branch Andrew Morton
@ 2026-12-02 18:47 ` Andrew Morton
  3 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2026-12-02 18:47 UTC (permalink / raw)
  To: mm-commits, joe, apw, elsk, akpm


The patch titled
     Subject: checkpatch: externalize function-like type macros
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     checkpatch-externalize-function-like-type-macros.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/checkpatch-externalize-function-like-type-macros.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: HONG Yifan <elsk@google.com>
Subject: checkpatch: externalize function-like type macros
Date: Wed, 18 Nov 2026 19:39:19 +0000

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").

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.

Link: https://patch.msgid.link/20261118193921.683813-1-elsk@google.com
Signed-off-by: HONG Yifan <elsk@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>

 MAINTAINERS                    |    1 +
 scripts/checkpatch.pl          |    9 +++++++--
 scripts/type_macros.checkpatch |    6 ++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

--- a/MAINTAINERS~checkpatch-externalize-function-like-type-macros
+++ a/MAINTAINERS
@@ -6265,6 +6265,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
--- a/scripts/checkpatch.pl~checkpatch-externalize-function-like-type-macros
+++ a/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 a/scripts/type_macros.checkpatch
new file mode 100644
--- /dev/null
+++ a/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
_

Patches currently in -mm which might be from elsk@google.com are

checkpatch-externalize-function-like-type-macros.patch


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-02 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 19:39 [PATCH v2] checkpatch: externalize function-like type macros 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
2026-12-02 18:45 ` + checkpatch-externalize-function-like-type-macros.patch added to mm-nonmm-unstable branch Andrew Morton
2026-12-02 18:47 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.