linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miles Chen <miles.chen@mediatek.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: <linux-kernel@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>, <wsd_upstream@mediatek.com>,
	Miles Chen <miles.chen@mediatek.com>,
	Yingjoe Chen <yingjoe.chen@mediatek.com>
Subject: [PATCH v2] checkpatch: add several Kconfig default value tests
Date: Thu, 4 Jul 2019 17:40:24 +0800	[thread overview]
Message-ID: <20190704094024.16162-1-miles.chen@mediatek.com> (raw)

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


             reply	other threads:[~2019-07-04  9:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  9:40 Miles Chen [this message]
2019-07-04 18:49 ` [PATCH v2] checkpatch: add several Kconfig default value tests Joe Perches
2019-07-05  2:06   ` Miles Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190704094024.16162-1-miles.chen@mediatek.com \
    --to=miles.chen@mediatek.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=wsd_upstream@mediatek.com \
    --cc=yingjoe.chen@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).