Skip to content

Commit f758440

Browse files
Taylor Nelmsakpm00
authored andcommitted
checkpatch: exclude forward declarations of const structs
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. Link: https://lkml.kernel.org/r/20260331181509.1258693-1-tknelms@google.com Signed-off-by: Taylor Nelms <tknelms@google.com> Acked-by: Joe Perches <joe@perches.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Dwaipayan Ray <dwaipayanray1@gmail.com> Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent cc82b3d commit f758440

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

scripts/checkpatch.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7512,10 +7512,10 @@ sub process {
75127512
}
75137513

75147514
# check for various structs that are normally const (ops, kgdb, device_tree)
7515-
# and avoid what seem like struct definitions 'struct foo {'
7515+
# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;'
75167516
if (defined($const_structs) &&
75177517
$line !~ /\bconst\b/ &&
7518-
$line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
7518+
$line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) {
75197519
WARN("CONST_STRUCT",
75207520
"struct $1 should normally be const\n" . $herecurr);
75217521
}

0 commit comments

Comments
 (0)