Skip to contentSkip to conversation

checkpatch: add --fix option for INCLUDE_LINUX

PATCH Superseded Dwaipayan Ray 2 participants 3 messages Nov 21, 2020 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: add --fix option for INCLUDE_LINUX

Provide fix option to INCLUDE_LINUX check to replace asm includes.

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

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

---
 scripts/checkpatch.pl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +5 -2
index 0da6422cd0fd..f852f130e065 100755
@@ -5468,8 +5468,11 @@ sub process {
 						CHK("ARCH_INCLUDE_LINUX",
 						    "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
 					} 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/\<asm\/$file\>/\<linux\/$file\>/;
+						}
 					}
 				}
 			}
Signature · 6 lines
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
maintainer
#1 lore raw
Quoted 8 lines · Dwaipayan Ray

Provide fix option to INCLUDE_LINUX check to replace asm includes.

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

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

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 5474

Quoted 10 lines
scripts/checkpatch.pl +4 -2
@@ -5468,8 +5468,11 @@ sub process {
  						CHK("ARCH_INCLUDE_LINUX",
  						    "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
  					} 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/\<asm\/$file\>/\<linux\/$file\>/;

$file can include a slash.

e.g.: arch/arm/kernel/atags_parse.c:#include <asm/mach/arch.h>

Probably simpler to use /Q /E quoting.

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw
Quoted 26 lines · Joe Perches
Quoted 8 lines · Dwaipayan Ray

Provide fix option to INCLUDE_LINUX check to replace asm includes.

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

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

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 5474

Quoted 10 lines
scripts/checkpatch.pl +4 -2
@@ -5468,8 +5468,11 @@ sub process {
                                              CHK("ARCH_INCLUDE_LINUX",
                                                  "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
                                      } 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/\<asm\/$file\>/\<linux\/$file\>/;

$file can include a slash.

Quoted 5 lines

e.g.: arch/arm/kernel/atags_parse.c:#include <asm/mach/arch.h>

Probably simpler to use /Q /E quoting.

Thanks. I will do that.

Regards,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees