History

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.

Joe Perches committed 11 years ago

Commit ea4acbb1 parent e0d975b1 file · +21 −3Browse files

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

Unified · Split

scripts/checkpatch.pl+21−3
@@ -3844,9 +3844,27 @@ sub process { · 3843 unmodified lines
3844# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar3844# 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 however3869#goto labels aren't indented, allow a single space however
3852 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and3870 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and