From: Taylor Nelms Date: Tue, 31 Mar 2026 18:15:09 +0000 (-0400) Subject: checkpatch: exclude forward declarations of const structs X-Git-Tag: v7.1-rc1~126^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f758440d3d82f2e1804d7df281a64d9ad88b7f52;p=thirdparty%2Fkernel%2Flinux.git 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 Acked-by: Joe Perches Cc: Andy Whitcroft Cc: Dwaipayan Ray Cc: Lukas Bulwahn Signed-off-by: Andrew Morton --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 27a43a4d9c438..7e612d3e2c1a1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7512,10 +7512,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); }