Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753293AbbBSTzr (ORCPT ); Thu, 19 Feb 2015 14:55:47 -0500 Received: from smtprelay0110.hostedemail.com ([216.40.44.110]:58734 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752177AbbBSTzq (ORCPT ); Thu, 19 Feb 2015 14:55:46 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:599: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:2691:2828:3138:3139:3140:3141:3142:3353:3622:3865:3867:3868:3870:3871:3872:3873:3874:4321:4605:5007:6261:10004:10400:10450:10455:10848:11026:11232:11473:11658:11914:12043:12295:12438:12517:12519:12555:12740:13069:13071:13161:13229:13311:13357:19904:19999:21060: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: rake28_6c35d0889b326 X-Filterd-Recvd-Size: 2614 Message-ID: <1424375741.18211.4.camel@perches.com> Subject: Re: checkpatch: CHECK: No space is necessary after a cast From: Joe Perches To: Marek Lindner Cc: "b.a.t.m.a.n" , linux-kernel@vger.kernel.org, Dan Carpenter Date: Thu, 19 Feb 2015 11:55:41 -0800 In-Reply-To: <2621923.3aVJ40SYcy@voltaire> References: <2621923.3aVJ40SYcy@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: 1981 Lines: 57 On Thu, 2015-02-19 at 13:35 +0800, Marek Lindner wrote: > Hi Joe, Hi Marek > we have come across a checkpatch false-positive: [] > BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6); > CHECK: No space is necessary after a cast > #440: FILE: main.c:440: > + BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6); [] > Can you make a suggestion / patch for checkpatch to better handle this case ? The "sizeof" test in the current script doesn't work. I believe the patch below works with no false positives but it's perl regexes against odd coding styles and weird macros, who knows for sure... I did run it against drivers/, net/ and include/ Give this a try: --- scripts/checkpatch.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d124359..2f5bb27 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2552,9 +2552,15 @@ 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 + if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$))/ && + (!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/