* [PATCH] checkpatch: warn if <foo.h> is already included
@ 2016-11-24 14:45 Geliang Tang
2016-11-24 15:55 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2016-11-24 14:45 UTC (permalink / raw)
To: Andy Whitcroft, Joe Perches; +Cc: Geliang Tang, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] checkpatch: warn if <foo.h> is already included
2016-11-24 14:45 [PATCH] checkpatch: warn if <foo.h> is already included Geliang Tang
@ 2016-11-24 15:55 ` Joe Perches
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2016-11-24 15:55 UTC (permalink / raw)
To: Geliang Tang, Andy Whitcroft; +Cc: linux-kernel
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 <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
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 <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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-24 15:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24 14:45 [PATCH] checkpatch: warn if <foo.h> is already included Geliang Tang
2016-11-24 15:55 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).