mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@shadowen.org>
Cc: David Cohen <david.a.cohen@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH V2] checkpatch: Improve "return is not a function" test
Date: Thu, 31 Oct 2013 16:12:44 -0700	[thread overview]
Message-ID: <1383261164.2769.6.camel@joe-AO722> (raw)
In-Reply-To: <1383075490.12439.26.camel@joe-AO722>

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>
---

V2: Add example to commit message.
    No change in patch itself.

 scripts/checkpatch.pl | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23d55bf..957ba04 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3221,21 +3221,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);
 
@@ -3244,6 +3233,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;




  parent reply	other threads:[~2013-10-31 23:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29 18:05 [PATCH 1/2] spi: add Intel Mid SSP driver David Cohen
2013-10-29 18:05 ` [PATCH 2/2] MAINTAINERS: add Intel MID SSP SPI maintainers David Cohen
2013-10-29 18:20   ` Joe Perches
2013-10-29 18:33     ` David Cohen
2013-10-29 18:57   ` Mark Brown
2013-10-29 18:19 ` [PATCH 1/2] spi: add Intel Mid SSP driver Joe Perches
2013-10-29 18:30   ` David Cohen
2013-10-29 18:35     ` Joe Perches
2013-10-29 19:32       ` David Cohen
2013-10-29 19:38         ` Joe Perches
2013-10-29 20:28           ` [PATCH] checkpatch: Improve "return is not a function" test Joe Perches
2013-10-31 23:12           ` Joe Perches [this message]
2013-11-01  1:03             ` [PATCH V2] " David Cohen
2013-11-04 22:21             ` Andrew Morton
2013-11-04 22:24               ` Joe Perches
2013-10-29 18:29 ` [PATCH 1/2] spi: add Intel Mid SSP driver Randy Dunlap
2013-10-29 18:35   ` David Cohen
2013-10-29 18:31 ` Felipe Balbi
2013-10-29 20:18   ` David Cohen
2013-10-30  3:26     ` Ning Li
2013-10-29 18:56 ` Mark Brown
2013-10-29 20:08   ` David Cohen
2013-10-30  1:42 ` Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383261164.2769.6.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@shadowen.org \
    --cc=david.a.cohen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®