diff options
author | Joe Perches <joe@perches.com> | 2015-04-16 15:44:22 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:03:57 -0400 |
commit | ab7e23f3448e55f4808f443a7b98ded6707701bb (patch) | |
tree | 7e1411de9380c8a312cd4a7c9bb6b83a89d6ceb0 /scripts | |
parent | f34e4a4f979c0d39f741bc809127fcf2167a7389 (diff) |
checkpatch: add test for repeated const uses
Using 'const <type> const *' is generally meant to be written 'const
<type> * const'.
Add a test for the miswritten form.
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 45babf2243f3..d54a814a4bc8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -323,6 +323,7 @@ our $Operators = qr{ | |||
323 | 323 | ||
324 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; | 324 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; |
325 | 325 | ||
326 | our $BasicType; | ||
326 | our $NonptrType; | 327 | our $NonptrType; |
327 | our $NonptrTypeMisordered; | 328 | our $NonptrTypeMisordered; |
328 | our $NonptrTypeWithAttr; | 329 | our $NonptrTypeWithAttr; |
@@ -514,6 +515,11 @@ sub build_types { | |||
514 | my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; | 515 | my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; |
515 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; | 516 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; |
516 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; | 517 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; |
518 | $BasicType = qr{ | ||
519 | (?:$typeOtherOSTypedefs\b)| | ||
520 | (?:$typeTypedefs\b)| | ||
521 | (?:${all}\b) | ||
522 | }x; | ||
517 | $NonptrType = qr{ | 523 | $NonptrType = qr{ |
518 | (?:$Modifier\s+|const\s+)* | 524 | (?:$Modifier\s+|const\s+)* |
519 | (?: | 525 | (?: |
@@ -3192,6 +3198,18 @@ sub process { | |||
3192 | $herecurr); | 3198 | $herecurr); |
3193 | } | 3199 | } |
3194 | 3200 | ||
3201 | # check for const <foo> const where <foo> is not a pointer or array type | ||
3202 | if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { | ||
3203 | my $found = $1; | ||
3204 | if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { | ||
3205 | WARN("CONST_CONST", | ||
3206 | "'const $found const *' should probably be 'const $found * const'\n" . $herecurr); | ||
3207 | } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { | ||
3208 | WARN("CONST_CONST", | ||
3209 | "'const $found const' should probably be 'const $found'\n" . $herecurr); | ||
3210 | } | ||
3211 | } | ||
3212 | |||
3195 | # check for non-global char *foo[] = {"bar", ...} declarations. | 3213 | # check for non-global char *foo[] = {"bar", ...} declarations. |
3196 | if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { | 3214 | if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { |
3197 | WARN("STATIC_CONST_CHAR_ARRAY", | 3215 | WARN("STATIC_CONST_CHAR_ARRAY", |