Skip to contentSkip to conversation

staging: pi433: remove unnecessary parentheses

PATCH In review Valentin Vidic 4 participants 8 messages Jan 8, 2018 – Jan 10, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: pi433: remove unnecessary parentheses

Fixes checkpatch warnings:

CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

---
 drivers/staging/pi433/rf69.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/pi433/rf69.c +3 -3
index bdd00f750765..a07fc6bc27f7 100644
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {
 		dev_dbg(&spi->dev, "set: illegal input param");
 		return -EINVAL;
 	}
Signature · 1 line
2.15.1
#1 lore raw
Quoted 16 lines · Valentin Vidic

Fixes checkpatch warnings:

CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

---
 drivers/staging/pi433/rf69.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/pi433/rf69.c +0 -0
index bdd00f750765..a07fc6bc27f7 100644

drivers/staging/pi433/rf69.c static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, · line 396

Quoted 9 lines
drivers/staging/pi433/rf69.c +3 -3
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {

I'm getting really tired of seeing this checkpatch warning, when it's a major pain.

Joe, can you please turn these off. Patches like this will force people to have to remember that != is higher precidence than &&. The original code here was just fine.

thanks,

greg k-h

Quoted 10 lines
drivers/staging/pi433/rf69.c +0 -0
 		dev_dbg(&spi->dev, "set: illegal input param");
 		return -EINVAL;
 	}
Signature · 6 lines
2.15.1

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
maintainer
#2 lore raw
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Valentin Vidic

Fixes checkpatch warnings:
CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

[]

Quoted 1 line

drivers/staging/pi433/rf69.c

Quoted 1 line
drivers/staging/pi433/rf69.c +0 -0

[]

Quoted 4 lines
Quoted 4 lines
drivers/staging/pi433/rf69.c +0 -0
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
Quoted 9 lines

drivers/staging/pi433/rf69.c static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, · line 396

Quoted 6 lines
drivers/staging/pi433/rf69.c +3 -3
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {

I'm getting really tired of seeing this checkpatch warning, when it's a major pain.

Your idea of major pain and mine differ a bit.

Quoted 2 lines

Joe, can you please turn these off. Patches like this will force people to have to remember that != is higher precidence than &&.

As it's not just 1 precedence level but 4 and 5, it really shouldn't be that hard to remember.

Quoted 1 line

The original code here was just fine.

And I don't really disagree with you.

David Miller has a preference for the parenthesis free style. I believe he mentioned it sometime in August 2017 but I can't find it right now.

Anyway, perhaps

---
 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 the 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);
#3 lore raw
Quoted 23 lines · Joe Perches
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Valentin Vidic

Fixes checkpatch warnings:
CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

[]

Quoted 1 line

drivers/staging/pi433/rf69.c

Quoted 1 line
drivers/staging/pi433/rf69.c +0 -0

[]

Quoted 4 lines
Quoted 4 lines
drivers/staging/pi433/rf69.c +0 -0
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
Quoted 9 lines

drivers/staging/pi433/rf69.c static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, · line 396

Quoted 6 lines
drivers/staging/pi433/rf69.c +3 -3
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {

I'm getting really tired of seeing this checkpatch warning, when it's a major pain.

Quoted 1 line

Your idea of major pain and mine differ a bit.

I don't like taking patches that cause future problems.

Quoted 5 lines
Quoted 2 lines

Joe, can you please turn these off. Patches like this will force people to have to remember that != is higher precidence than &&.

As it's not just 1 precedence level but 4 and 5, it really shouldn't be that hard to remember.

I can't remember any of them, and I should not have to. That's the point, you should not assume anyone knows the levels, code is written for developers to understand first, and the compiler second. By removing these, it doesn't do anything for the compiler, but makes the developer think longer about them.

Quoted 18 lines
Quoted 1 line

The original code here was just fine.

And I don't really disagree with you.

David Miller has a preference for the parenthesis free style. I believe he mentioned it sometime in August 2017 but I can't find it right now.

Anyway, perhaps

---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index d2464058ab5d..3a7499de2c2d 100755

scripts/checkpatch.pl sub process { · line 4531

Quoted 7 lines
scripts/checkpatch.pl +3 -1
@@ -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 the command-line uses --strict
+		if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
+		    $^V && $^V ge 5.10.0 && defined($stat) &&

How about only if in the networking area? I don't want to take patches for this for other parts of the kernel either, it's really useless.

thanks,

greg k-h

maintainer
#4 lore raw
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Joe Perches
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Valentin Vidic

Fixes checkpatch warnings:
CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

[]

Quoted 1 line

drivers/staging/pi433/rf69.c

Quoted 1 line
drivers/staging/pi433/rf69.c +0 -0

[]

Quoted 13 lines

drivers/staging/pi433/rf69.c static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, · line 396

Quoted 10 lines
drivers/staging/pi433/rf69.c +3 -3
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {

I'm getting really tired of seeing this checkpatch warning, when it's a major pain.

Quoted 3 lines
Quoted 1 line

Your idea of major pain and mine differ a bit.

I don't like taking patches that cause future problems.

What future problems might this particular case present that isn't generic in all patches.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Joe, can you please turn these off. Patches like this will force people to have to remember that != is higher precidence than &&.

As it's not just 1 precedence level but 4 and 5, it really shouldn't be that hard to remember.

I can't remember any of them, and I should not have to.

That depends on how well you know your C.

Quoted 3 lines

That's the
point, you should not assume anyone knows the levels, code is written for developers to understand first, and the compiler second.

And someone that knows C knows those levels and the parentheses can just be visual noise requiring extra thought.

Sometimes it's useful, sometimes it's not.

	if (a == b && c == d)

is pretty trivial.

and I believe

	if ((a == b))

emits clang warnings

Quoted 3 lines

By
removing these, it doesn't do anything for the compiler, but makes the developer think longer about them.

Generally I have to think more with more parentheses.

Quoted 20 lines
Quoted 20 lines
Quoted 1 line

The original code here was just fine.

And I don't really disagree with you.

David Miller has a preference for the parenthesis free style. I believe he mentioned it sometime in August 2017 but I can't find it right now.

Anyway, perhaps

---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index d2464058ab5d..3a7499de2c2d 100755
@@ -4526,7 +4526,9 @@ sub process {
 		}
 
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 4531

Quoted 5 lines
scripts/checkpatch.pl +3 -1
 # check for unnecessary parentheses around comparisons in if uses
-		if ($^V && $^V ge 5.10.0 && defined($stat) &&
+# when !drivers/staging or the command-line uses --strict
+		if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
+		    $^V && $^V ge 5.10.0 && defined($stat) &&

How about only if in the networking area? I don't want to take patches for this for other parts of the kernel either, it's really useless.

AFAIK: Almost no one thinks when sending staging patches.

For other parts of the tree, it requires --strict on the command line. AFAIK: almost no one uses that and if they do, then they can determine for themselves if they want to remove excessive parentheses.

#5 lore raw
Quoted 37 lines · Joe Perches
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Joe Perches
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Valentin Vidic

Fixes checkpatch warnings:
CHECK: Unnecessary parentheses around 'mantisse != mantisse16'
CHECK: Unnecessary parentheses around 'mantisse != mantisse20'
CHECK: Unnecessary parentheses around 'mantisse != mantisse24'

[]

Quoted 1 line

drivers/staging/pi433/rf69.c

Quoted 1 line
drivers/staging/pi433/rf69.c +0 -0

[]

Quoted 13 lines

drivers/staging/pi433/rf69.c static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, · line 396

Quoted 10 lines
drivers/staging/pi433/rf69.c +3 -3
@@ -391,9 +391,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
 		return -EINVAL;
 	}
 
-	if ((mantisse != mantisse16) &&
-	    (mantisse != mantisse20) &&
-	    (mantisse != mantisse24)) {
+	if (mantisse != mantisse16 &&
+	    mantisse != mantisse20 &&
+	    mantisse != mantisse24) {

I'm getting really tired of seeing this checkpatch warning, when it's a major pain.

Quoted 3 lines
Quoted 1 line

Your idea of major pain and mine differ a bit.

I don't like taking patches that cause future problems.

What future problems might this particular case present that isn't generic in all patches.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

Joe, can you please turn these off. Patches like this will force people to have to remember that != is higher precidence than &&.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

As it's not just 1 precedence level but 4 and 5, it really shouldn't be that hard to remember.

I can't remember any of them, and I should not have to.

That depends on how well you know your C.

I have used C for almost ever single day for the past 20+ years, and I sure don't remember the order of these things. But maybe I really don't know my C :)

Quoted 4 lines
Quoted 3 lines

That's the
point, you should not assume anyone knows the levels, code is written for developers to understand first, and the compiler second.

Quoted 8 lines

And someone that knows C knows those levels and the parentheses can just be visual noise requiring extra thought.

Sometimes it's useful, sometimes it's not.

	if (a == b && c == d)

is pretty trivial.

But again, don't do that.

Quoted 5 lines

and I believe

	if ((a == b))

emits clang warnings

Then remove the extra () there.

thanks,

greg k-h

maintainer
#6 lore raw
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines · Joe Perches
	if (a == b && c == d)

is pretty trivial.

But again, don't do that.

<shrug> We disagree. Life goes on.

cheers, Joe

#7 lore raw

Joe Perches schrieb am 10.01.2018 10:05:

Quoted 12 lines · Greg Kroah-Hartman
Quoted 5 lines · Joe Perches
Quoted 2 lines

if (a == b && c == d)
is pretty trivial.

But again, don't do that.

<shrug> We disagree. Life goes on.

cheers, Joe

For me the line above isn't obvious and easy to read. If I would be in doubt, whether it really performs correctly, I would have to ask the c-guide, to be absolutely shure. But to be honest: If I need to find a bug arround taht lines, I wouldn't ask the c-guide, but simply add some (). Then it would be 100% clear and no one would be in doubt any more.

What's the disadvantage of () to emphasise waht is going on. An other Option for me would be, to spend a command line and write that info in form of a comment.

Just my opinion and the way, I would go on if I am in doubt and need to find a bug.

Cheers,

Marcus