From: Geliang Tang <geliangtang@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: Geliang Tang <geliangtang@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: warn if <foo.h> is already included
Date: Thu, 24 Nov 2016 22:45:52 +0800 [thread overview]
Message-ID: <eba72e0dc08c5c80017000bf555d59f686423a36.1479998643.git.geliangtang@gmail.com> (raw)
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 <linux/string.h>, this header is already included
+#include <linux/string.h>
WARNING: Do not use #include <linux/string.h>, this header is already included
+#include <linux/string.h>
total: 0 errors, 4 warnings, 589 lines checked
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
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 <foo.h> 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
next reply other threads:[~2016-11-24 14:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-24 14:45 Geliang Tang [this message]
2016-11-24 15:55 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eba72e0dc08c5c80017000bf555d59f686423a36.1479998643.git.geliangtang@gmail.com \
--to=geliangtang@gmail.com \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®