diff mbox

checkpatch: Add warning with unnecessary parentheses in if statements

Message ID 1387760575.22671.36.camel@joe-AO722
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Joe Perches Dec. 23, 2013, 1:02 a.m. UTC
Using doubled parentheses in statements like "if ((foo == bar))"
is unnecessary or may be a sign of an intended single assignment
instead of a comparison.

Bleat a warning message on those uses.

Signed-off-by: Joe Perches <joe@perches.com>
---
> > On Sun, 2013-12-22 at 18:12 -0500, David Miller wrote:
> >> > +	if ((mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
> >> > +	if ((mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
> >> > +	if ((mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
> >> > +	    (mdev->dev->caps.tunnel_offload_mode ==  MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
> >> > +	if ((mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
> >> 
> >> Way too many parenthesis, this isn't LISP :-)
> > 
> > Is patchwork stuttering?
> 
> I edited it, I'm quoting all of the lines in your patch that add the
> "too many parenthsis" problem.

OK then.  Or's patch, not mine, but maybe this is useful...

(this also happened today with another nominal cleanup patch)

 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8f3aecd..29af02a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3251,6 +3251,13 @@  sub process {
 			}
 		}
 
+# if statements using unnecessary parentheses - ie: if ((foo == bar))
+		if ($^V && $^V ge 5.10.0 &&
+		    $line =~ /\bif\s*\(\s*\(\s*$LvalOrFunc\s*$Compare\s*$LvalOrFunc\s*\)\s*\)/) {
+			WARN("UNNECESSARY_PARENTHESES",
+			     "Unnecessary parentheses\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;