lkml.org 
[lkml]   [2016]   [Nov]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] checkpatch: warn if <foo.h> is already included
Date
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
\
 
 \ /
  Last update: 2016-11-24 15:46    [W:0.074 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site