From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755871AbbE2JM2 (ORCPT ); Fri, 29 May 2015 05:12:28 -0400 Received: from smtprelay0033.hostedemail.com ([216.40.44.33]:59543 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755727AbbE2JMV (ORCPT ); Fri, 29 May 2015 05:12:21 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 10,1,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:196:355:379:541:800:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1622:1711:1730:1747:1777:1792:1801:2197:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4605:5007:6261:7903:10004:10400:10848:11232:11658:11914:12043:12114:12295:12296:12517:12519:12555:12663:12740:13019:13071:13095:13221:13229:14093:14097:14394: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: girl90_6b88deadee51a X-Filterd-Recvd-Size: 3044 Message-ID: <1432890738.29807.6.camel@perches.com> Subject: [PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test From: Joe Perches To: Andrew Morton Cc: Bandan Das , Andy Whitcroft , linux-kernel@vger.kernel.org Date: Fri, 29 May 2015 02:12:18 -0700 In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 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 commit d5e616fc1c1d ("checkpatch: add a few more --fix corrections") broke the GLOBAL_INITIALISERS test with bad parentheses and optional leading spaces. Fix it. Reported-by: Bandan Das Signed-off-by: Joe Perches --- On Thu, 2015-05-28 at 23:41 -0400, Bandan Das wrote: > Hi Joe, Hi Bandan. > Sorry, I am very Perl illiterate but I was deliberately trying to hit the > "do not initialize globals" message from checkpatch.pl and can't seem to. > > Looking at the corresponding regexp, it seems the correct pattern should be: > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -3169,7 +3169,7 @@ sub process { > } > > # check for global initialisers. > - if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) { > + if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/) { > if (ERROR("GLOBAL_INITIALISERS", > "do not initialise globals to 0 or NULL\n" . > $herecurr) && > > which matches zero or more of $Modifier followed by zero or more of a space. > Or am I missing something ? No, you're right, thanks, but the proper fix is a bit more than that and it's below. scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 4650c04..e46414d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3176,12 +3176,12 @@ sub process { } # check for global initialisers. - if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) { + if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*(?:0|NULL|false)\s*;/) { if (ERROR("GLOBAL_INITIALISERS", "do not initialise globals to 0 or NULL\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/; + $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/$1;/; } } # check for static initialisers.