All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: add several Kconfig default value tests
@ 2019-07-04  9:40 ` Miles Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Miles Chen @ 2019-07-04  9:40 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches
  Cc: linux-kernel, linux-mediatek, wsd_upstream, Miles Chen, Yingjoe Chen

This change adds 3 Kconfig default value tests:

1. discourage default n cases:
e.g.,
default n

2. discourage default "[ynm]" cases:
e.g.,
arch/powerpc/Kconfig:   default "y" if PPC_POWERNV
arch/powerpc/Kconfig:   default "y" if PPC_POWERNV
arch/powerpc/Kconfig:   default "n"
drivers/auxdisplay/Kconfig:     default "n"
drivers/crypto/Kconfig: default "m"
drivers/rapidio/devices/Kconfig:        default "n"

3. discourage default \!?EXPERT cases:
e.g.,
drivers/hid/Kconfig:    default !EXPERT

tested cases:
default m
default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
default y if ALPHA_QEMU
default n if PPC_POWERNV
default n
default EXPERT
default !EXPERT
default "m"
default "n"
default "y" if EXPERT
default "y" if PPC_POWERNV

test result:
WARNING: 'default n' is the default value, no need to write it explicitly.
+       default n

WARNING: Avoid default turn on kernel configs by default !?EXPERT
+       default EXPERT

WARNING: Avoid default turn on kernel configs by default !?EXPERT
+       default !EXPERT

WARNING: Use default [ynm] instead of default "[ynm]"
+       default "m"

WARNING: Use default [ynm] instead of default "[ynm]"
+       default "n"

WARNING: Use default [ynm] instead of default "[ynm]"
+       default "y" if EXPERT

WARNING: Use default [ynm] instead of default "[ynm]"
+       default "y" if PPC_POWERNV

Change since v1:
discourage default n$
discourage default "[ynm]"
discourage default \!?EXPERT

Cc: Joe Perches <joe@perches.com>
Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
Signed-off-by: Miles Chen <miles.chen@mediatek.com>
---
 scripts/checkpatch.pl | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 342c7c781ba5..c1de50202a18 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3005,6 +3005,27 @@ sub process {
 			     "Use of boolean is deprecated, please use bool instead.\n" . $herecurr);
 		}
 
+# discourage redundant 'default n'
+		if ($realfile =~ /Kconfig/ &&
+		    $line =~ /^\+\s*default n$/) {
+			WARN("DEFAULT_VALUE_STYLE",
+			     "'default n' is the default value, no need to write it explicitly.\n" . $herecurr);
+		}
+
+# discourage quote: use default [ynm], not default "[ynm]"
+		if ($realfile =~ /Kconfig/ &&
+		    $rawline =~ /^\+\s*default\s*"[ynm]"/) {
+			WARN("DEFAULT_VALUE_STYLE",
+			     "Use default [ynm] instead of default \"[ynm]\"\n" . $herecurr);
+		}
+
+# discourage default \!?EXPERT
+		if ($realfile =~ /Kconfig/ &&
+		    $line =~ /^\+\s*default \!?EXPERT/) {
+			WARN("DEFAULT_VALUE_STYLE",
+			     "Avoid default turn on kernel configs by default !?EXPERT\n" . $herecurr);
+		}
+
 		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
 		    ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
 			my $flag = $1;
-- 
2.18.0


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

end of thread, other threads:[~2019-07-05  2:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04  9:40 [PATCH v2] checkpatch: add several Kconfig default value tests Miles Chen
2019-07-04  9:40 ` Miles Chen
2019-07-04 18:49 ` Joe Perches
2019-07-05  2:06   ` Miles Chen
2019-07-05  2:06     ` Miles Chen

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.