Skip to contentSkip to conversation

+ checkpatch-make-return-is-not-a-function-test-quieter.patch added to -mm tree

PATCH [email protected] 1 participant 1 message Feb 27, 2014 Checkpatch

lore
Share & tools
lore
#0 lore raw

Subject: + checkpatch-make-return-is-not-a-function-test-quieter.patch added to -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Thu, 27 Feb 2014 14:23:01 -0800

The patch titled
Subject: checkpatch: make "return is not a function" test quieter
has been added to the -mm tree. Its filename is
checkpatch-make-return-is-not-a-function-test-quieter.patch

This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/checkpatch-make-return-is-not-a-function-test-quieter.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/checkpatch-make-return-is-not-a-function-test-quieter.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: Joe Perches <[email protected]>
Subject: checkpatch: make "return is not a function" test quieter

This test is a bit noisy and opinions seem to agree that it should not warn in a lot more situations.

It seems people agree that:

	return (foo || bar);
and
	return foo || bar;

are both acceptable style and checkpatch should be silent about them.

For now, it warns on parentheses around a simple constant or a single function or a ternary.

	return (foo);
	return (foo(bar));
	return (foo ? bar : baz);

The last ternary test may be quieted in the future.

Modify the deparenthesize function to only strip balanced leading and trailing parentheses.

Cc Julia Lawall <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Monam Agarwal <[email protected]>
Cc Greg KH <[email protected]>

---

 scripts/checkpatch.pl |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-make-return-is-not-a-function-test-quieter +15 -7
diff -puN scripts/checkpatch.pl~checkpatch-make-return-is-not-a-function-test-quieter scripts/checkpatch.pl
@@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOr
 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);

_

Patches currently in -mm which might be from [email protected] are

origin.patch
maintainers-use-tab-for-separator.patch maintainers-add-and-correct-types-of-some-t-entries.patch lib-random32c-minor-cleanups-and-kdoc-fix.patch mm-utilc-add-kstrimdup.patch checkpatch-add-test-for-long-udelay.patch checkpatch-dont-warn-on-some-function-pointer-return-styles.patch checkpatch-add-checks-for-constant-non-octal-permissions.patch checkpatch-warn-on-uses-of-__constant_foo-functions.patch checkpatch-update-octal-permissions-warning.patch checkpatch-avoid-sscanf-test-duplicated-messages.patch checkpatch-fix-jiffies-comparison-and-others.patch checkpatch-add-test-for-char-arrays-that-could-be-static-const.patch checkpatch-use-a-more-consistent-function-argument-style.patch checkpatch-ignore-networking-block-comment-style-first-lines-in-file.patch checkpatch-make-return-is-not-a-function-test-quieter.patch ncpfs-add-pr_fmt-and-convert-printks-to-pr_level.patch ncpfs-convert-dprintk-ddprintk-to-ncp_dbg.patch ncpfs-convert-dprintk-ddprintk-to-ncp_dbg-fix.patch ncpfs-convert-dprintk-ddprintk-to-ncp_dbg-fix-fix.patch ncpfs-convert-pprintk-to-ncp_vdbg.patch ncpfs-remove-now-unused-printk-macro.patch ncpfs-inode-fix-mismatch-printk-formats-and-arguments.patch linux-next.patch