Commit d9190e4e authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

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.

Link: http://lkml.kernel.org/r/0dce709150d712e66f1b90b03827634b53b28085.1491845946.git.joe@perches.comSigned-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Arthur Brainville <ybalrid@ybalrid.info>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eb3a58de
...@@ -6090,11 +6090,11 @@ sub process { ...@@ -6090,11 +6090,11 @@ sub process {
} }
# check for various structs that are normally const (ops, kgdb, device_tree) # check for various structs that are normally const (ops, kgdb, device_tree)
# and avoid what seem like struct definitions 'struct foo {'
if ($line !~ /\bconst\b/ && if ($line !~ /\bconst\b/ &&
$line =~ /\bstruct\s+($const_structs)\b/) { $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
WARN("CONST_STRUCT", WARN("CONST_STRUCT",
"struct $1 should normally be const\n" . "struct $1 should normally be const\n" . $herecurr);
$herecurr);
} }
# use of NR_CPUS is usually wrong # use of NR_CPUS is usually wrong
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment