diff options
author | Joe Perches <joe@perches.com> | 2014-12-11 00:51:51 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-11 02:41:12 +0100 |
commit | ea4acbb11e32a2a1e7d80aa3d3039f909647ceee (patch) | |
tree | 8faec310c2965f428c2c1e2c7a97852108204b15 /scripts | |
parent | checkpatch: reduce MAINTAINERS update message frequency (diff) | |
download | linux-ea4acbb11e32a2a1e7d80aa3d3039f909647ceee.tar.xz linux-ea4acbb11e32a2a1e7d80aa3d3039f909647ceee.zip |
checkpatch: Add --strict test for function pointer calling style
Peter Hurley wrote:
The use of older function ptr calling style, (*fn)(), makes static
analysis more error-prone; replace with modern fn() style.
So make checkpatch emit a --strict test for that condition.
Update the unnecessary parentheses test for dereferencing
objects at the same time and create a $fix mechanism too.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Peter Hurley <peter@hurleysoftware.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 | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 41e7db451cc0..893cbd517f89 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3844,9 +3844,27 @@ sub process { # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) { - CHK("UNNECESSARY_PARENTHESES", - "Unnecessary parentheses around $1\n" . $herecurr); - } + my $var = $1; + if (CHK("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses around $var\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/; + } + } + +# check for unnecessary parentheses around function pointer uses +# ie: (foo->bar)(); should be foo->bar(); +# but not "if (foo->bar) (" to avoid some false positives + if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) { + my $var = $2; + if (CHK("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses around function pointer $var\n" . $herecurr) && + $fix) { + my $var2 = deparenthesize($var); + $var2 =~ s/\s//g; + $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/; + } + } #goto labels aren't indented, allow a single space however if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |