checkpatch: make "return is not a function" test quieter
[linux-2.6-block.git] / scripts / checkpatch.pl
index c624b04d0070d476bc74f49586e4b1e599ee8ba8..f0ea8a037a6dc0f61230587a50abaadcd95662aa 100755 (executable)
@@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
 sub deparenthesize {
        my ($string) = @_;
        return "" if (!defined($string));
-       $string =~ s@^\s*\(\s*@@g;
-       $string =~ s@\s*\)\s*$@@g;
+
+       while ($string =~ /^\s*\(.*\)\s*$/) {
+               $string =~ s@^\s*\(\s*@@;
+               $string =~ s@\s*\)\s*$@@;
+       }
+
        $string =~ s@\s+@ @g;
+
        return $string;
 }
 
@@ -3374,14 +3379,17 @@ sub process {
                        }
                }
 
-# Return is not a function.
+# return is not a function
                if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
                        my $spacing = $1;
                        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);
-
+                           $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
+                               my $value = $1;
+                               $value = deparenthesize($value);
+                               if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
+                                       ERROR("RETURN_PARENTHESES",
+                                             "return is not a function, parentheses are not required\n" . $herecurr);
+                               }
                        } elsif ($spacing !~ /\s+/) {
                                ERROR("SPACING",
                                      "space required before the open parenthesis '('\n" . $herecurr);