checkpatch: add Kconfig 'default n' test
PATCH v3 1/2 checkpatch: add Kconfig 'default n' test
If a Kconfig config option doesn't specify 'default', the default will be n. Adding 'default n' is unnecessary.
Add a test to warn about this.
---
For this series, rebase to v4.7-rc1 and dropped 'relax Kconfig help text line number threshold' patch.
Let me know what you think. Thanks.
Change in v3:
- Rebase to v4.7-rc1
Change in v2:
- Change according to Joe Perches' suggesti
scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+)
scripts/checkpatch.pl +7 -0
@@ -2683,6 +2683,13 @@ sub process { "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); } +# discourage the use of default n + if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*default\s*n\s*(#.*|$)/i) { + WARN("CONFIG_DEFAULT_N", + "Use of default n is unnecessary, default is n when omitted.\n" . $herecurr); + } + if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { my $flag = $1;
Signature · 1 line
1.9.1
PATCH v3 2/2 checkpatch: testing more config for Kconfig help text
Current help text check only check a config option if it is followed by another config.
Adding check for help text if the next entry is menuconfig, choice/ endchoice, comment, menu/endmenu, if/endif, source or end of file.
--- scripts/checkpatch.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +7 -1
@@ -2646,6 +2646,12 @@ sub process { next if ($f =~ /^-/); last if (!$file && $f =~ /^\@\@/); + if ($f !~ /^[+\- ]/) { + # End of file + $is_end = 1; + last; + } + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate)\s*\"/) { $is_start = 1; } elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
@@ -2656,7 +2662,7 @@ sub process { $f =~ s/#.*//; $f =~ s/^\s+//; next if ($f =~ /^$/); - if ($f =~ /^\s*config\s/) { + if ($f =~ /^(?:config\s|menuconfig\s|choice\s|endchoice\s*$|comment\s|menu\s|endmenu\s*$|if\s|endif\s*$|source\s)/) { $is_end = 1; last; }
Signature · 1 line
1.9.1
Joe Perches
maintainerQuoted 3 lines · Yingjoe Chen
If a
Kconfigconfig option doesn't specify 'default', the default will be n. Adding 'default n' is unnecessary.
Add a test to warn about this.
Is it obvious that a Kconfig has "default n" ?
This seems to work, but is this useful?
Quoted 35 lines
Signed-off-by Yingjoe Chen <[email protected]>---
For this series, rebase to v4.7-rc1 and dropped 'relaxKconfighelp text line number threshold' patch.Let me know what you think. Thanks.
Change in v3:
- Rebase to v4.7-rc1Change in v2:
- Change according to Joe Perches' suggestiscripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)scripts/checkpatch.pl +0
-0@@ -2683,6 +2683,13 @@ sub process { "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); }scripts/checkpatch.pl +7
-0+# discourage the use of default n + if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*default\s*n\s*(#.*|$)/i) { + WARN("CONFIG_DEFAULT_N", + "Use of default n is unnecessary, default is n when omitted.\n" . $herecurr); + } +if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
my $flag = $1;
Andy Whitcroft
maintainerQuoted 10 lines · Joe Perches
Quoted 3 lines · Yingjoe Chen
If a
Kconfigconfig option doesn't specify 'default', the default will be n. Adding 'default n' is unnecessary.
Add a test to warn about this.Is it obvious that a
Kconfighas "default n" ?
This seems to work, but is this useful?scripts/checkpatch.pl sub process { · line 2688
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*default\s*n\s*(#.*|$)/i) {
I wonder particually when the submitter has supplied a comment, presumably to tell us why it defaults to 'n'. I feel more accepting of rejecting uncommented ones than those with.
Quoted 7 lines
Quoted 7 lines
scripts/checkpatch.pl +4
-0+ WARN("CONFIG_DEFAULT_N", + "Use of default n is unnecessary, default is n when omitted.\n" . $herecurr); + } +if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
my $flag = $1;
-apw
Hi,
Thanks for the review.
Quoted 8 lines · Andy Whitcroft
Quoted 7 lines · Joe Perches
Quoted 3 lines · Yingjoe Chen
If a
Kconfigconfig option doesn't specify 'default', the default will be n. Adding 'default n' is unnecessary.
Add a test to warn about this.Is it obvious that a
Kconfighas "default n" ?
This seems to work, but is this useful?
While sending patch for upstream, I saw maintainers request it to be removed. So I think it might worth adding check to it. Some examples from google:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-September/120733.html
https://lkml.org/lkml/2013/3/16/153
https://lkml.org/lkml/2016/5/23/657
Quoted 7 lines
Quoted 3 lines
scripts/checkpatch.pl sub process { · line 2688
Quoted 3 lines
scripts/checkpatch.pl +2
-0+ if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*default\s*n\s*(#.*|$)/i) {I wonder particually when the submitter has supplied a comment, presumably to tell us why it defaults to 'n'. I feel more accepting of rejecting uncommented ones than those with.
How about change this to /^\+\s*default\s*n$/i ?
Joe.C
Quoted 4 lines · Yingjoe Chen
Quoted 2 lines · Andy Whitcroft
Quoted 2 lines
Is it obvious that a
Kconfighas "default n" ?
This seems to work, but is this useful?
Quoted 8 lines
While sending patch for upstream, I saw maintainers request it to be removed. So I think it might worth adding check to it. Some examples from google:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-September/1
20733.html
https://lkml.org/lkml/2013/3/16/153
https://lkml.org/lkml/2016/5/23/657
There's one rather subtle case where setting "default n" is, sort of, useful. See lkml.kernel.org/r/<178407860.0zoJnDfCo1@tacticalops> .
(I seem to remember disagreeing here. Ie, in my view setting defaults for a specific Kconfig symbol at two different places is confusing at best. People probably weren't convinced by my objections. I also remember diving into this by looking at the various places where a Kconfig symbol was being set twice. I must have ended that endeavor when it became clear to me I was't making any progress.)
Even though there's a corner case where "default n" is useful, it could still be worth to add a checkpatch check that warns about it. But I can't say I feel strongly about this either way.
Paul Bolle