From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966261AbcKXPzh (ORCPT ); Thu, 24 Nov 2016 10:55:37 -0500 Received: from smtprelay0212.hostedemail.com ([216.40.44.212]:51570 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965931AbcKXPzf (ORCPT ); Thu, 24 Nov 2016 10:55:35 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599: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:2198:2199:2200:2393:2559:2562:2828:2903:3138:3139:3140:3141:3142:3353:3622:3653:3865:3866:3868:3870:3871:3874:4321:5007:7514:10004:10400:10848:11232:11658:11914:12043:12555:12679:12740:12760:13069:13161:13229:13311:13357:13439:14181:14659:14721:21080:21221:21451:30054:30091,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,LFtime:3,LUA_SUMMARY:none X-HE-Tag: touch59_87dda9b34b322 X-Filterd-Recvd-Size: 2499 Message-ID: <1480002931.19726.9.camel@perches.com> Subject: Re: [PATCH] checkpatch: warn if is already included From: Joe Perches To: Geliang Tang , Andy Whitcroft Cc: linux-kernel@vger.kernel.org Date: Thu, 24 Nov 2016 07:55:31 -0800 In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.1-0ubuntu2 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, 2016-11-24 at 22:45 +0800, Geliang Tang wrote: > Some headers are included twice. Emit a warning when they occur. > For example: > $ ./scripts/checkpatch.pl -f drivers/of/overlay.c > WARNING: Do not use #include , this header is already included > +#include > > WARNING: Do not use #include , this header is already included > +#include > > total: 0 errors, 4 warnings, 589 lines checked There already is a script that looks for duplicate #include uses so I think this isn't particularly useful or necessary. see: scripts/checkincludes.h Also, this doesn't work when reordering #include lines. . > Signed-off-by: Geliang Tang > --- > scripts/checkpatch.pl | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 1579230..a0792d6 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -4749,6 +4749,18 @@ sub process { > } > } > > +# warn if is already #included > + if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<(.*)\.h\>}) { > + my $file = "$1.h"; > + if (-f "$root/$realfile") { > + my $asminclude = `grep -Ec "#include\\s+<$file>" $root/$realfile`; > + if ($asminclude > 1) { > + WARN("INCLUDE_LINUX", > + "Do not use #include <$file>, this header is already included\n" . $herecurr); > + } > + } > + } > + > # multi-statement macros should be enclosed in a do while loop, grab the > # first statement and ensure its the whole macro if its not enclosed > # in a known good container