From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S944031AbdDTQt6 (ORCPT ); Thu, 20 Apr 2017 12:49:58 -0400 Received: from smtprelay0120.hostedemail.com ([216.40.44.120]:47396 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S942369AbdDTQtz (ORCPT ); Thu, 20 Apr 2017 12:49:55 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:69:355:379:541:599:800:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1605:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:2693:2736:2828:3138:3139:3140:3141:3142:3167:3622:3653:3865:3866:3867:3868:3871:3872:3874:4321:4605:5007:7875:7903:8957:9040:9121:10004:10400:10848:11232:11233:11658:11914:12043:12291:12296:12555:12663:12683:12740:12760:12895:13439:14181:14659:14721:21080:21222:21451:30012:30054:30062:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: map39_900032d9cd94a X-Filterd-Recvd-Size: 4494 Message-ID: <1492706988.30293.13.camel@perches.com> Subject: Re: [PATCH] checkpatch: add --typedefsfile From: Joe Perches To: Jerome Forissier , Andy Whitcroft , linux-kernel@vger.kernel.org Cc: Andrew Morton Date: Thu, 20 Apr 2017 09:49:48 -0700 In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 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 On Thu, 2017-04-20 at 17:39 +0200, Jerome Forissier wrote: > When using checkpatch on out-of-tree code, it may occur that some > project-specific types are used, which will cause spurious warnings. > Add the --typedefsfile option as a way to extend the known types and > deal with this issue. I'm not opposed to the addition. What out-of-tree project is this for? > Signed-off-by: Jerome Forissier > --- > scripts/checkpatch.pl | 56 ++++++++++++++++++++++++++++++++++----------------- > 1 file changed, 37 insertions(+), 19 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index baa3c7b..eb55f5f 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -55,6 +55,7 @@ my $spelling_file = "$D/spelling.txt"; > my $codespell = 0; > my $codespellfile = "/usr/share/codespell/dictionary.txt"; > my $conststructsfile = "$D/const_structs.checkpatch"; > +my $typedefsfile = ""; > my $color = 1; > my $allow_c99_comments = 1; > > @@ -113,6 +114,7 @@ Options: > --codespell Use the codespell dictionary for spelling/typos > (default:/usr/share/codespell/dictionary.txt) > --codespellfile Use this codespell dictionary > + --typedefsfile Read additional types from this file > --color Use colors when output is STDOUT (default: on) > -h, --help, --version display this help and exit > > @@ -208,6 +210,7 @@ GetOptions( > 'test-only=s' => \$tst_only, > 'codespell!' => \$codespell, > 'codespellfile=s' => \$codespellfile, > + 'typedefsfile=s' => \$typedefsfile, > 'color!' => \$color, > 'h|help' => \$help, > 'version' => \$help > @@ -629,28 +632,43 @@ if ($codespell) { > > $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; > > +sub read_words { > + my ($wordsRef, $file) = @_; > + > + if (open(my $words, '<', $file)) { > + while (<$words>) { > + my $line = $_; > + > + $line =~ s/\s*\n?$//g; > + $line =~ s/^\s*//g; > + > + next if ($line =~ m/^\s*#/); > + next if ($line =~ m/^\s*$/); > + if ($line =~ /\s/) { > + print("$file: '$line' invalid - ignored\n"); > + next; > + } > + > + $$wordsRef .= '|' if ($$wordsRef ne ""); > + $$wordsRef .= $line; > + } > + close($file); > + return 1; > + } > + > + return 0; > +} > + > my $const_structs = ""; > -if (open(my $conststructs, '<', $conststructsfile)) { > - while (<$conststructs>) { > - my $line = $_; > +read_words(\$const_structs, $conststructsfile) > + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; > > - $line =~ s/\s*\n?$//g; > - $line =~ s/^\s*//g; > - > - next if ($line =~ m/^\s*#/); > - next if ($line =~ m/^\s*$/); > - if ($line =~ /\s/) { > - print("$conststructsfile: '$line' invalid - ignored\n"); > - next; > - } > - > - $const_structs .= '|' if ($const_structs ne ""); > - $const_structs .= $line; > - } > - close($conststructsfile); > -} else { > - warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; > +my $typeOtherTypedefs = ""; > +if (length($typedefsfile)) { > + read_words(\$typeOtherTypedefs, $typedefsfile) > + or warn "No additional types will be considered - file '$typedefsfile': $!\n"; > } > +$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); > > sub build_types { > my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";