checkpatch: add --fix option for INCLUDE_LINUX
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
@@ -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
Quoted 10 lines · Dwaipayan Ray
Provide fix option to
INCLUDE_LINUXcheck to replace asm includes.Macros of type:
#include <asm/percpu.h>are corrected to:
#include <linux/percpu.h>
The patch itself looks okay; but should this fix option not be limited to lines where content is added?
Further we need to investigate:
- is this still a valid rule?
- is this rule and the rationale documented somewhere?
- how many rule violations currently exist in the kernel repository?
- are there known exceptions for some files in some directories?
Lukas
Quoted 24 lines
Signed-off-by Dwaipayan Ray <[email protected]>--- scripts/checkpatch.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)scripts/checkpatch.pl +5
-3@@ -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\>/; + } } } } --
Quoted 2 lines
2.27.0
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 9 lines · Lukas Bulwahn
Quoted 7 lines · Dwaipayan Ray
Provide fix option to
INCLUDE_LINUXcheck to replace asm includes.Macros of type:
#include <asm/percpu.h>
Quoted 7 lines
Quoted 3 lines
are corrected to:
#include <linux/percpu.h>The patch itself looks okay; but should this fix option not be limited to lines where content is added?
Hi,
I think the warning itself is emitted for lines which are added. So I think the fix option even now will change those added lines only.
Quoted 3 lines
Further we need to investigate:
- is this still a valid rule?
- is this rule and the rationale documented somewhere?
I think the rule is valid. I was going through the documentation files and in several examples I saw that the linux headers are preferred.
Like in Documentation/core-api/local_ops.rst:
91:
#include <linux/percpu.h>
#include <asm/local.h>
In Documentation/trace/kprobes.rst:
362:
#include <linux/kprobes.h>
int register_kprobe(struct kprobe *kp);
400:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
int pre_handler(struct kprobe *p, struct pt_regs *regs);
410:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
void post_handler(struct kprobe *p, struct pt_regs *regs,
unsigned long flags);
and so on...
I didn't find any explicit mention about absolutely preffering linux headers over asm headers whenever it exists.
Quoted 2 lines
- how many rule violations currently exist in the kernel repository?
- are there known exceptions for some files in some directories?
There are exceptions to this.
Like in include/linux/percpu.h,
#include <asm/percpu.h> needs to be included. as linux/percpu wraps over asm/percpu. So these kinds are exempted from the check and checkpatch doesn't report any warning.
I did find some violations like in arch/csky/kernel/probes/decode-insn.h:
CHECK: Consider using #include <linux/kprobes.h> instead of <asm/kprobes.h> #7: FILE: arch/csky/kernel/probes/decode-insn.h:7:
+#include <asm/kprobes.h>
I found one commit which fixed one such case in the kernel:
commit ca5999fde0a17 ("mm: introduce include/linux/pgtable.h") It says "The include/linux/pgtable.h is going to be the home of generic page table
manipulation functions."
So I think it means that future additings should use <linux/pgtable.h> instead of
<asm/pgtable.h>
I think the ARCH_INCLUDE_LINUX also deserves a --fix option similarly.
What do you think? Should I continue with this?
Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 78 lines · Dwaipayan Ray
Quoted 9 lines · Lukas Bulwahn
Quoted 7 lines · Dwaipayan Ray
Provide fix option to
INCLUDE_LINUXcheck to replace asm includes.Macros of type:
#include <asm/percpu.h>Quoted 7 lines
Quoted 3 lines
are corrected to:
#include <linux/percpu.h>The patch itself looks okay; but should this fix option not be limited to lines where content is added?
Hi,
I think the warning itself is emitted for lines which are added. So I think the fix option even now will change those added lines only.Quoted 3 lines
Further we need to investigate:
- is this still a valid rule?
- is this rule and the rationale documented somewhere?I think the rule is valid. I was going through the documentation files and in several examples I saw that the linux headers are preferred.
Like in
Documentation/core-api/local_ops.rst:91:
#include <linux/percpu.h> #include <asm/local.h>In
Documentation/trace/kprobes.rst:362:
#include <linux/kprobes.h>
intregister_kprobe(struct kprobe *kp);400:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
intpre_handler(struct kprobe *p, struct pt_regs *regs);410:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
void post_handler(struct kprobe *p, structpt_regs*regs,
unsigned long flags);and so on...
I didn't find any explicit mention about absolutely preffering linux headers over asm headers whenever it exists.
Quoted 2 lines
- how many rule violations currently exist in the kernel repository?
- are there known exceptions for some files in some directories?There are exceptions to this.
Like ininclude/linux/percpu.h,
#include <asm/percpu.h> needs to be included. as linux/percpu wraps over asm/percpu. So these kinds are exempted from the check and checkpatch doesn't report any warning.I did find some violations like in
arch/csky/kernel/probes/decode-insn.h:
CHECK: Consider using #include <linux/kprobes.h> instead of <asm/kprobes.h> #7: FILE:arch/csky/kernel/probes/decode-insn.h:7:
+#include <asm/kprobes.h>I found one commit which fixed one such case in the kernel:
commitca5999fde0a17("mm: introduceinclude/linux/pgtable.h") It says "Theinclude/linux/pgtable.his going to be the home of generic page table
manipulation functions."
Quoted 8 lines
So I think it means that future additings should use <
linux/pgtable.h> instead of
<asm/pgtable.h>I think the
ARCH_INCLUDE_LINUXalso deserves a --fix option similarly.What do you think? Should I continue with this?
Yes, that is good. Thanks for the investigation.
You can consider to:
- also fix the cases where this rule is violated and send patches to the maintainers.
- add some documentation on this rule.
Lukas
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 89 lines · Lukas Bulwahn
Quoted 78 lines · Dwaipayan Ray
Quoted 9 lines · Lukas Bulwahn
Quoted 7 lines · Dwaipayan Ray
Provide fix option to
INCLUDE_LINUXcheck to replace asm includes.Macros of type:
#include <asm/percpu.h>Quoted 7 lines
Quoted 3 lines
are corrected to:
#include <linux/percpu.h>The patch itself looks okay; but should this fix option not be limited to lines where content is added?
Hi,
I think the warning itself is emitted for lines which are added. So I think the fix option even now will change those added lines only.Quoted 3 lines
Further we need to investigate:
- is this still a valid rule?
- is this rule and the rationale documented somewhere?I think the rule is valid. I was going through the documentation files and in several examples I saw that the linux headers are preferred.
Like in
Documentation/core-api/local_ops.rst:91:
#include <linux/percpu.h> #include <asm/local.h>In
Documentation/trace/kprobes.rst:362:
#include <linux/kprobes.h>
intregister_kprobe(struct kprobe *kp);400:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
intpre_handler(struct kprobe *p, struct pt_regs *regs);410:
#include <linux/kprobes.h>
#include <linux/ptrace.h>
void post_handler(struct kprobe *p, structpt_regs*regs,
unsigned long flags);and so on...
I didn't find any explicit mention about absolutely preffering linux headers over asm headers whenever it exists.
Quoted 2 lines
- how many rule violations currently exist in the kernel repository?
- are there known exceptions for some files in some directories?There are exceptions to this.
Like ininclude/linux/percpu.h,
#include <asm/percpu.h> needs to be included. as linux/percpu wraps over asm/percpu. So these kinds are exempted from the check and checkpatch doesn't report any warning.I did find some violations like in
arch/csky/kernel/probes/decode-insn.h:
CHECK: Consider using #include <linux/kprobes.h> instead of <asm/kprobes.h> #7: FILE:arch/csky/kernel/probes/decode-insn.h:7:
+#include <asm/kprobes.h>I found one commit which fixed one such case in the kernel:
commitca5999fde0a17("mm: introduceinclude/linux/pgtable.h") It says "Theinclude/linux/pgtable.his going to be the home of generic page table
manipulation functions."Quoted 8 lines
So I think it means that future additings should use <
linux/pgtable.h> instead of
<asm/pgtable.h>I think the
ARCH_INCLUDE_LINUXalso deserves a --fix option similarly.What do you think? Should I continue with this?
Quoted 8 lines
Yes, that is good. Thanks for the investigation.
You can consider to:
- also fix the cases where this rule is violated and send patches to the maintainers.
- add some documentation on this rule.
Okay sure I will try doing that.
I am just sending this patch unchanged to Joe and LKML to have their review. If it is ok, I will get on with the next task.
Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees