All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] checkpatch: add --fix option to include linux checks
@ 2020-12-06 15:23 ` Dwaipayan Ray
  0 siblings, 0 replies; 6+ messages in thread
From: Dwaipayan Ray @ 2020-12-06 15:23 UTC (permalink / raw)
  To: joe; +Cc: linux-kernel-mentees, dwaipayanray1, linux-kernel, lukas.bulwahn

Add fix option to INCLUDE_LINUX and ARCH_INCLUDE_LINUX
checks to replace asm includes.

Macros of type:
 #include <asm/percpu.h>
 #include <asm/processor.h>

are corrected to:
 #include <linux/percpu.h>
 #include <linux/processor.h>

Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
Changes in v3:
- Add --fix option to ARCH_INCLUDE_LINUX check

Changes in v2:
- Use \Q..\E quoting
- Use @ as regex delimiter

 scripts/checkpatch.pl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b086d1cd6c2..4aecc237ed38 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5558,11 +5558,17 @@ sub process {
 				my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
 				if ($asminclude > 0) {
 					if ($realfile =~ m{^arch/}) {
-						CHK("ARCH_INCLUDE_LINUX",
-						    "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+						if (CHK("ARCH_INCLUDE_LINUX",
+							"Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr) &&
+						    $fix) {
+							$fixed[$fixlinenr] =~ s@\Q<asm/$file>\E@<linux/$file>@;
+						}
 					} else {
-						WARN("INCLUDE_LINUX",
-						     "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+						if (WARN("INCLUDE_LINUX",
+							 "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr) &&
+						    $fix) {
+							$fixed[$fixlinenr] =~ s@\Q<asm/$file>\E@<linux/$file>@;
+						}
 					}
 				}
 			}
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-09 15:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-06 15:23 [PATCH v3] checkpatch: add --fix option to include linux checks Dwaipayan Ray
2020-12-06 15:23 ` [Linux-kernel-mentees] " Dwaipayan Ray
2020-12-09  9:17 ` Lukas Bulwahn
2020-12-09  9:17   ` [Linux-kernel-mentees] " Lukas Bulwahn
2020-12-09 15:22   ` Dwaipayan Ray
2020-12-09 15:22     ` [Linux-kernel-mentees] " Dwaipayan Ray

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.