Skip to content

Commit

Permalink
checkpatch: improve "return is not a function" test
Browse files Browse the repository at this point in the history
Find a few more cases where parentheses are used around the value of a
return statement.

This now uses the "$balanced_parens" test and also makes the test depend
on perl v5.10 and higher.

This now finds return with parenthesis uses the old code did not find
like:

ERROR: return is not a function, parentheses are not required
torvalds#211: FILE: arch/m68k/include/asm/sun3xflop.h:211:
+		return ((error == 0) ? 0 : -1);

Signed-off-by: Joe Perches <[email protected]>
Tested-by: David Cohen <[email protected]>
Acked-by: David Cohen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Nov 13, 2013
1 parent 4783f89 commit 507e514
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3233,21 +3233,10 @@ sub process {
}

# Return is not a function.
if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
my $spacing = $1;
my $value = $2;

# Flatten any parentheses
$value =~ s/\(/ \(/g;
$value =~ s/\)/\) /g;
while ($value =~ s/\[[^\[\]]*\]/1/ ||
$value !~ /(?:$Ident|-?$Constant)\s*
$Compare\s*
(?:$Ident|-?$Constant)/x &&
$value =~ s/\([^\(\)]*\)/1/) {
}
#print "value<$value>\n";
if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
if ($^V && $^V ge 5.10.0 &&
$stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
ERROR("RETURN_PARENTHESES",
"return is not a function, parentheses are not required\n" . $herecurr);

Expand All @@ -3256,6 +3245,7 @@ sub process {
"space required before the open parenthesis '('\n" . $herecurr);
}
}

# Return of what appears to be an errno should normally be -'ve
if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
my $name = $1;
Expand Down

0 comments on commit 507e514

Please sign in to comment.