* [PATCH] checkpatch: exclude forward declarations of const structs
@ 2026-03-31 17:26 Taylor Nelms
2026-03-31 17:46 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Taylor Nelms @ 2026-03-31 17:26 UTC (permalink / raw)
To: Joe Perches, Andy Whitcroft
Cc: Taylor Nelms, Dwaipayan Ray, Lukas Bulwahn, linux-kernel
Limit checkpatch warnings for normally-const structs by excluding
patterns consistent with forward declarations.
For example, the forward declaration `struct regmap_access_table;` in a
header file currently generates a warning recommending that it is
generally declared as const; however, this would apply a useless type
qualifier in the empty declaration `const struct regmap_access_table;`,
and subsequently generate compiler warnings.
Signed-off-by: Taylor Nelms <tknelms@google.com>
---
scripts/checkpatch.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff7..47bce7e7aeba 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7502,10 +7502,10 @@ sub process {
}
# check for various structs that are normally const (ops, kgdb, device_tree)
-# and avoid what seem like struct definitions 'struct foo {'
+# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;'
if (defined($const_structs) &&
$line !~ /\bconst\b/ &&
- $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
+ $line =~ /\bstruct\s+($const_structs)\b(?!\s*(\{|;))/) {
WARN("CONST_STRUCT",
"struct $1 should normally be const\n" . $herecurr);
}
--
2.53.0.1118.gaef5881109-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] checkpatch: exclude forward declarations of const structs
2026-03-31 17:26 [PATCH] checkpatch: exclude forward declarations of const structs Taylor Nelms
@ 2026-03-31 17:46 ` Joe Perches
2026-03-31 18:15 ` [PATCH v2] " Taylor Nelms
0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2026-03-31 17:46 UTC (permalink / raw)
To: Taylor Nelms, Andy Whitcroft; +Cc: Dwaipayan Ray, Lukas Bulwahn, linux-kernel
On Tue, 2026-03-31 at 13:26 -0400, Taylor Nelms wrote:
> ```
> Limit checkpatch warnings for normally-const structs by excluding
> patterns consistent with forward declarations.
>
> For example, the forward declaration `struct regmap_access_table;` in a
> header file currently generates a warning recommending that it is
> generally declared as const; however, this would apply a useless type
> qualifier in the empty declaration `const struct regmap_access_table;`,
> and subsequently generate compiler warnings.
>
> Signed-off-by: Taylor Nelms <[tknelms@google.com](mailto:tknelms@google.com)>
Seems sensible, thanks but:
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7502,10 +7502,10 @@ sub process {
> }
>
> # check for various structs that are normally const (ops, kgdb, device_tree)
> -# and avoid what seem like struct definitions 'struct foo {'
> +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;'
> if (defined($const_structs) &&
> $line !~ /\bconst\b/ &&
> - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
> + $line =~ /\bstruct\s+($const_structs)\b(?!\s*(\{|;))/) {
Prefer using (?:\{|;) to avoid capture groups or maybe [\{;]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] checkpatch: exclude forward declarations of const structs
2026-03-31 17:46 ` Joe Perches
@ 2026-03-31 18:15 ` Taylor Nelms
2026-03-31 18:43 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Taylor Nelms @ 2026-03-31 18:15 UTC (permalink / raw)
To: Joe Perches, Andy Whitcroft
Cc: Taylor Nelms, Dwaipayan Ray, Lukas Bulwahn, linux-kernel
Limit checkpatch warnings for normally-const structs by excluding
patterns consistent with forward declarations.
For example, the forward declaration `struct regmap_access_table;` in a
header file currently generates a warning recommending that it is
generally declared as const; however, this would apply a useless type
qualifier in the empty declaration `const struct regmap_access_table;`,
and subsequently generate compiler warnings.
Signed-off-by: Taylor Nelms <tknelms@google.com>
---
Changelog since v1:
- Changed capturing group to character class in regex.
scripts/checkpatch.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff7..bed0bfedf5ba 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7502,10 +7502,10 @@ sub process {
}
# check for various structs that are normally const (ops, kgdb, device_tree)
-# and avoid what seem like struct definitions 'struct foo {'
+# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;'
if (defined($const_structs) &&
$line !~ /\bconst\b/ &&
- $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
+ $line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) {
WARN("CONST_STRUCT",
"struct $1 should normally be const\n" . $herecurr);
}
--
2.53.0.1118.gaef5881109-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] checkpatch: exclude forward declarations of const structs
2026-03-31 18:15 ` [PATCH v2] " Taylor Nelms
@ 2026-03-31 18:43 ` Joe Perches
0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2026-03-31 18:43 UTC (permalink / raw)
To: Taylor Nelms, Andy Whitcroft, Andrew Morton
Cc: Dwaipayan Ray, Lukas Bulwahn, linux-kernel
On Tue, 2026-03-31 at 14:15 -0400, Taylor Nelms wrote:
> Limit checkpatch warnings for normally-const structs by excluding
> patterns consistent with forward declarations.
>
> For example, the forward declaration `struct regmap_access_table;` in a
> header file currently generates a warning recommending that it is
> generally declared as const; however, this would apply a useless type
> qualifier in the empty declaration `const struct regmap_access_table;`,
> and subsequently generate compiler warnings.
>
> Signed-off-by: Taylor Nelms <[tknelms@google.com](mailto:tknelms@google.com)>
Acked-by: Joe Perches <joe@perches.com>
> ---
>
> Changelog since v1:
> - Changed capturing group to character class in regex.
>
> scripts/checkpatch.pl | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e56374662ff7..bed0bfedf5ba 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -7502,10 +7502,10 @@ sub process {
> }
>
> # check for various structs that are normally const (ops, kgdb, device_tree)
> -# and avoid what seem like struct definitions 'struct foo {'
> +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;'
> if (defined($const_structs) &&
> $line !~ /\bconst\b/ &&
> - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
> + $line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) {
> WARN("CONST_STRUCT",
> "struct $1 should normally be const\n" . $herecurr);
> }
>
> ```
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-31 18:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-31 17:26 [PATCH] checkpatch: exclude forward declarations of const structs Taylor Nelms
2026-03-31 17:46 ` Joe Perches
2026-03-31 18:15 ` [PATCH v2] " Taylor Nelms
2026-03-31 18:43 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome