History

checkpatch: avoid suggesting struct definitions should be const

Many structs are generally used const and there is a known list of these structs. struct definitions should not be generally be declared const. Add a test for the lack of an open brace immediately after the struct to avoid definitions. This avoids the false positive "struct foo should normally be const" message only when the open brace is on the same line as the definition.

Joe Perches committed 9 years ago

Commit d9190e41 parent eb3a58d1 file · +3 −3Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+3−3
@@ -6090,11 +6090,11 @@ sub process { · 6089 unmodified lines
6090 }6090 }
6091 6091
6092# check for various structs that are normally const (ops, kgdb, device_tree)6092# check for various structs that are normally const (ops, kgdb, device_tree)
6093# and avoid what seem like struct definitions 'struct foo {'
6093 if ($line !~ /\bconst\b/ &&6094 if ($line !~ /\bconst\b/ &&
6094 $line =~ /\bstruct\s+($const_structs)\b/) {6095 $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
6095 WARN("CONST_STRUCT",6096 WARN("CONST_STRUCT",
6096 "struct $1 should normally be const\n" .6097 "struct $1 should normally be const\n" . $herecurr);
6097 $herecurr);
6098 }6098 }
6099 6099
6100# use of NR_CPUS is usually wrong6100# use of NR_CPUS is usually wrong