Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754970AbbBTTwk (ORCPT ); Fri, 20 Feb 2015 14:52:40 -0500 Received: from smtprelay0203.hostedemail.com ([216.40.44.203]:37629 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754445AbbBTTwj (ORCPT ); Fri, 20 Feb 2015 14:52:39 -0500 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:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3865:3868:3871:3872:3874:4321:5007:6261:10004:10400:10450:10455:10848:11026:11473:11658:11914:12043:12438:12517:12519:12555:13069:13161:13221:13229:13311:13357:14093:14097:14394:19904:19999:21080,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: sleet47_8b4187d70f230 X-Filterd-Recvd-Size: 2465 Message-ID: <1424461955.18211.15.camel@perches.com> Subject: [PATCH] checkpatch: Improve "no space is necessary after a cast" test From: Joe Perches To: Andrew Morton Cc: b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org, Dan Carpenter , Marek Lindner Date: Fri, 20 Feb 2015 11:52:35 -0800 In-Reply-To: <7679509.IB7arj1Sb8@voltaire> References: <2621923.3aVJ40SYcy@voltaire> <1424375741.18211.4.camel@perches.com> <7679509.IB7arj1Sb8@voltaire> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.7-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1728 Lines: 46 The "no space is necessary after a cast" sizeof exclusion doesn't work properly. The test reports a false positive for code like: BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6); Make it work, simplify the exclusions, and add some comments. Signed-off-by: Joe Perches Reported-by: Marek Lindner --- scripts/checkpatch.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d124359..2898e49 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2552,9 +2552,16 @@ sub process { } } - if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && - (!defined($1) || $1 !~ /sizeof\s*/)) { - if (CHK("SPACING", +# check for space after cast like "(int) foo" or "(struct foo) bar" +# avoid checking a few false positives: +# "sizeof()" or "__alignof__()" +# function pointer declarations like "(*foo)(int) = bar;" +# structure definitions like "(struct foo) { 0 };" +# multiline macros that define functions +# known attributes or the __attribute__ keyword + if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ && + (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) { + if (CHK("SPACING", "No space is necessary after a cast\n" . $herecurr) && $fix) { $fixed[$fixlinenr] =~ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/