From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941091AbcKXOqF (ORCPT ); Thu, 24 Nov 2016 09:46:05 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36354 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941034AbcKXOqC (ORCPT ); Thu, 24 Nov 2016 09:46:02 -0500 From: Geliang Tang To: Andy Whitcroft , Joe Perches Cc: Geliang Tang , linux-kernel@vger.kernel.org Subject: [PATCH] checkpatch: warn if is already included Date: Thu, 24 Nov 2016 22:45:52 +0800 Message-Id: X-Mailer: git-send-email 2.9.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 -- 2.9.3