Commit 507e5141 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: improve "return is not a function" test

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
#211: FILE: arch/m68k/include/asm/sun3xflop.h:211:
+		return ((error == 0) ? 0 : -1);
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Tested-by: default avatarDavid Cohen <david.a.cohen@linux.intel.com>
Acked-by: default avatarDavid Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4783f894
...@@ -3233,21 +3233,10 @@ sub process { ...@@ -3233,21 +3233,10 @@ sub process {
} }
# Return is not a function. # 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 $spacing = $1;
my $value = $2; if ($^V && $^V ge 5.10.0 &&
$stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
# 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*$/) {
ERROR("RETURN_PARENTHESES", ERROR("RETURN_PARENTHESES",
"return is not a function, parentheses are not required\n" . $herecurr); "return is not a function, parentheses are not required\n" . $herecurr);
...@@ -3256,6 +3245,7 @@ sub process { ...@@ -3256,6 +3245,7 @@ sub process {
"space required before the open parenthesis '('\n" . $herecurr); "space required before the open parenthesis '('\n" . $herecurr);
} }
} }
# Return of what appears to be an errno should normally be -'ve # Return of what appears to be an errno should normally be -'ve
if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
my $name = $1; my $name = $1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment