提交 ea4acbb1 编写于 作者: J Joe Perches 提交者: Linus Torvalds

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: NJoe Perches <joe@perches.com>
Cc: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 e0d975b1
......@@ -3844,8 +3844,26 @@ 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册