Skip to contentSkip to conversation

checkpatch: exclude drivers/staging from if with unnecessary parentheses test

PATCH Joe Perches 2 participants 4 messages Jan 11, 2018 – Jan 12, 2018 Checkpatch

lore
Share & tools
lore

Joe Perches

author maintainer
#0 lore raw

Greg KH doesn't like this test so exclude the staging directory from the implied --strict only test unless --strict is actually used on the command-line.

---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +3 -1
index d2464058ab5d..3a7499de2c2d 100755
@@ -4526,7 +4526,9 @@ sub process {
 		}
 
 # check for unnecessary parentheses around comparisons in if uses
-		if ($^V && $^V ge 5.10.0 && defined($stat) &&
+# when !drivers/staging or command-line uses --strict
+		if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
+		    $^V && $^V ge 5.10.0 && defined($stat) &&
 		    $stat =~ /(^.\s*if\s*($balanced_parens))/) {
 			my $if_stat = $1;
 			my $test = substr($2, 1, -1);
#1 lore raw
Quoted 4 lines · On Thu, 11 Jan 2018 12:53:54 -0800 Joe Perches <[email protected]> wrote:

Greg KH doesn't like this test so exclude the staging directory from the implied --strict only test unless --strict is actually used on the command-line.

"doesn't like" is rather vague. What is the objection, specifically?

Also, an example of code which has an "if with unnecessary parentheses" would help others understand the decision.

author maintainer
#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Thu, 11 Jan 2018 12:53:54 -0800 Joe Perches <[email protected]> wrote:

Greg KH doesn't like this test so exclude the staging directory from the implied --strict only test unless --strict is actually used on the command-line.

"doesn't like" is rather vague. What is the objection, specifically?

Unnecessary parentheses sometimes make code easier to read for those that don't know C very well. i.e.: Greg and maybe others too.

Quoted 2 lines

Also, an example of code which has an "if with unnecessary parentheses" would help others understand the decision.

	if ((foo == bar) &&
	    (baz != qux))

where the parentheses around the comparisons are generically unnecessary as the && is a much higher precedence than the comparisons.

#3 lore raw
Quoted 17 lines · On Thu, 11 Jan 2018 17:17:53 -0800 Joe Perches <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Thu, 11 Jan 2018 12:53:54 -0800 Joe Perches <[email protected]> wrote:

Greg KH doesn't like this test so exclude the staging directory from the implied --strict only test unless --strict is actually used on the command-line.

"doesn't like" is rather vague. What is the objection, specifically?

Unnecessary parentheses sometimes make code easier to read for those that don't know C very well. i.e.: Greg and maybe others too.

Quoted 2 lines

Also, an example of code which has an "if with unnecessary parentheses" would help others understand the decision.

Quoted 6 lines
	if ((foo == bar) &&
	    (baz != qux))

where the parentheses around the comparisons are generically unnecessary as the && is a much higher precedence than the comparisons.

OK, agree. I too don't like to be doubtfully staring at something trying to remember the precedence rules.

Within limits. There are of course cases where the parenthesization is silly (who doesn't know that * is higher than +?). But such silliness-detection is probably beyond checkpatch ;)