diff options
author | Joe Perches <joe@perches.com> | 2013-11-12 18:10:13 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 22:09:25 -0500 |
commit | 507e51418ca0c98640310aa02450720825b2b6b1 (patch) | |
tree | c31ed1d6e0fa1686ac3738aea997a82fc524bade /scripts | |
parent | 4783f894d0f3bfb107cf3b1d9aed1f1a0672ee1d (diff) |
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: Joe Perches <joe@perches.com>
Tested-by: David Cohen <david.a.cohen@linux.intel.com>
Acked-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ec9bbf863d50..6e0f1ec0d6f2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -3233,21 +3233,10 @@ sub process { | |||
3233 | } | 3233 | } |
3234 | 3234 | ||
3235 | # Return is not a function. | 3235 | # Return is not a function. |
3236 | if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) { | 3236 | if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { |
3237 | my $spacing = $1; | 3237 | my $spacing = $1; |
3238 | my $value = $2; | 3238 | if ($^V && $^V ge 5.10.0 && |
3239 | 3239 | $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { | |
3240 | # Flatten any parentheses | ||
3241 | $value =~ s/\(/ \(/g; | ||
3242 | $value =~ s/\)/\) /g; | ||
3243 | while ($value =~ s/\[[^\[\]]*\]/1/ || | ||
3244 | $value !~ /(?:$Ident|-?$Constant)\s* | ||
3245 | $Compare\s* | ||
3246 | (?:$Ident|-?$Constant)/x && | ||
3247 | $value =~ s/\([^\(\)]*\)/1/) { | ||
3248 | } | ||
3249 | #print "value<$value>\n"; | ||
3250 | if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { | ||
3251 | ERROR("RETURN_PARENTHESES", | 3240 | ERROR("RETURN_PARENTHESES", |
3252 | "return is not a function, parentheses are not required\n" . $herecurr); | 3241 | "return is not a function, parentheses are not required\n" . $herecurr); |
3253 | 3242 | ||
@@ -3256,6 +3245,7 @@ sub process { | |||
3256 | "space required before the open parenthesis '('\n" . $herecurr); | 3245 | "space required before the open parenthesis '('\n" . $herecurr); |
3257 | } | 3246 | } |
3258 | } | 3247 | } |
3248 | |||
3259 | # Return of what appears to be an errno should normally be -'ve | 3249 | # Return of what appears to be an errno should normally be -'ve |
3260 | if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { | 3250 | if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { |
3261 | my $name = $1; | 3251 | my $name = $1; |