Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754898AbbERSmS (ORCPT ); Mon, 18 May 2015 14:42:18 -0400 Received: from smtprelay0055.hostedemail.com ([216.40.44.55]:53189 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753427AbbERSmN (ORCPT ); Mon, 18 May 2015 14:42:13 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:800:960:969:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1431:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2693:2828:2892:3138:3139:3140:3141:3142:3355:3622:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:5007:6261:7514:7875:7903:8603:8957:9040:10004:10400:10848:11026:11232:11658:11914:12043:12296:12438:12517:12519:12555:12663:12740:13255: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: rain34_4cb6d1515b628 X-Filterd-Recvd-Size: 4435 Message-ID: <1431974526.2870.36.camel@perches.com> Subject: Re: [PATCH] checkpatch: types found in one source file do not affect processing of others From: Joe Perches To: Alex Dowad Cc: Andy Whitcroft , open list Date: Mon, 18 May 2015 11:42:06 -0700 In-Reply-To: <1431956009-16076-1-git-send-email-alexinbeijing@gmail.com> References: <1431956009-16076-1-git-send-email-alexinbeijing@gmail.com> 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 Content-Length: 3707 Lines: 111 On Mon, 2015-05-18 at 15:33 +0200, Alex Dowad wrote: > checkpatch uses various cues in its input files to discover the names of > user-defined types. It then uses that information when processing expressions, > to discover more style issues. > > Unfortunately, in rare cases, this means that checkpatch may give different > results if you run it on several files at the same time, or one by one! The > reason is that it may identify a type (or something that looks like a type) > in one file, and then carry this information over when processing a different > file. > > As an example, drivers/staging/media/bcm2048/radio-bcm2048.c contains this > line (in a macro): > > size value; > > Then drivers/staging/media/davinci_vpfe/vpfe_video.c has this line: > > while (size * *nbuffers > vpfe_dev->video_limit) > > If checkpatch processes these 2 files together, the (spurious) "size" type > detected in the first file will cause it to flag the second file for > improper use of the pointer dereference operator! > > Therefore, keep user-defined types in a separate array from built-in ones, > and reset the array of user-defined types at the beginning of each new > source file. > > Signed-off-by: Alex Dowad > --- > > Dear patch checkers, > > I am not a Perl programmer -- please let me know if there is a better way to > accomplish what I am trying to do here. > > Your feedback will be appreciated, > Alex Dowad > > scripts/checkpatch.pl | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) I suggest this: --- scripts/checkpatch.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 89b1df4..174d711 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -418,6 +418,7 @@ our @typeList = ( qr{${Ident}_handler_fn}, @typeListMisordered, ); +our @typeListFile = (); our @typeListWithAttr = ( @typeList, qr{struct\s+$InitAttribute\s+$Ident}, @@ -427,6 +428,7 @@ our @typeListWithAttr = ( our @modifierList = ( qr{fastcall}, ); +our @modifierListFile = (); our @mode_permission_funcs = ( ["module_param", 3], @@ -510,8 +512,8 @@ if ($codespell) { $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; sub build_types { - my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; - my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; + my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; + my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; @@ -746,6 +748,9 @@ for my $filename (@ARGV) { @fixed_inserted = (); @fixed_deleted = (); $fixlinenr = -1; + @modifierListFile = (); + @typeListFile = (); + build_types(); } exit($exit); @@ -1610,13 +1615,13 @@ sub possible { for my $modifier (split(' ', $possible)) { if ($modifier !~ $notPermitted) { warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); - push(@modifierList, $modifier); + push(@modifierListFile, $modifier); } } } else { warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); - push(@typeList, $possible); + push(@typeListFile, $possible); } build_types(); } else { -- 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/