From patchwork Mon Dec 23 01:02:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 304608 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3EB862C009F for ; Mon, 23 Dec 2013 12:03:32 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756617Ab3LWBDD (ORCPT ); Sun, 22 Dec 2013 20:03:03 -0500 Received: from smtprelay0164.hostedemail.com ([216.40.44.164]:45363 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756362Ab3LWBDC (ORCPT ); Sun, 22 Dec 2013 20:03:02 -0500 Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id B44706B636; Mon, 23 Dec 2013 01:03:00 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2, 0, 0, , d41d8cd98f00b204, joe@perches.com, :::::::::::::::, RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3870:3871:3872:3874:4321:5007:7652:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12050:12438:12517:12519:12555:12663:12740:13069:13095:13311:13357, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:0:0 X-HE-Tag: bells13_5421df3893400 X-Filterd-Recvd-Size: 2911 Received: from [192.168.1.157] (pool-96-251-49-11.lsanca.fios.verizon.net [96.251.49.11]) (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA; Mon, 23 Dec 2013 01:02:57 +0000 (UTC) Message-ID: <1387760575.22671.36.camel@joe-AO722> Subject: [PATCH] checkpatch: Add warning with unnecessary parentheses in if statements From: Joe Perches To: David Miller , Andrew Morton Cc: ogerlitz@mellanox.com, netdev@vger.kernel.org, amirv@mellanox.com, yanb@mellanox.com, ast@plumgrid.com, Andy Whitcroft Date: Sun, 22 Dec 2013 17:02:55 -0800 In-Reply-To: <20131222.191400.620087948725635345.davem@davemloft.net> References: <1387725972-10244-3-git-send-email-ogerlitz@mellanox.com> <20131222.181202.168681767663560253.davem@davemloft.net> <1387755159.22671.27.camel@joe-AO722> <20131222.191400.620087948725635345.davem@davemloft.net> X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- > > 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 --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;