aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-12-10 18:51:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-10 20:41:12 -0500
commitea4acbb11e32a2a1e7d80aa3d3039f909647ceee (patch)
tree8faec310c2965f428c2c1e2c7a97852108204b15 /scripts/checkpatch.pl
parente0d975b1b439c4fef58fbc306c542c94f48bb849 (diff)
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/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl24
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 {
3844# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar 3844# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
3845 3845
3846 while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) { 3846 while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
3847 CHK("UNNECESSARY_PARENTHESES", 3847 my $var = $1;
3848 "Unnecessary parentheses around $1\n" . $herecurr); 3848 if (CHK("UNNECESSARY_PARENTHESES",
3849 } 3849 "Unnecessary parentheses around $var\n" . $herecurr) &&
3850 $fix) {
3851 $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
3852 }
3853 }
3854
3855# check for unnecessary parentheses around function pointer uses
3856# ie: (foo->bar)(); should be foo->bar();
3857# but not "if (foo->bar) (" to avoid some false positives
3858 if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
3859 my $var = $2;
3860 if (CHK("UNNECESSARY_PARENTHESES",
3861 "Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
3862 $fix) {
3863 my $var2 = deparenthesize($var);
3864 $var2 =~ s/\s//g;
3865 $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
3866 }
3867 }
3850 3868
3851#goto labels aren't indented, allow a single space however 3869#goto labels aren't indented, allow a single space however
3852 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 3870 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and