diff mbox

[1/3] checkpatch: add Kconfig 'default n' test

Message ID 1461245285-14918-1-git-send-email-yingjoe.chen@mediatek.com
State Superseded
Headers show

Commit Message

Yingjoe Chen April 21, 2016, 1:28 p.m. UTC
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.

Signed-off-by: Yingjoe Chen <yingjoe.chen@mediatek.com>

---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
1.9.1

Comments

Yingjoe Chen April 22, 2016, 2:19 p.m. UTC | #1
On Thu, 2016-04-21 at 10:16 -0700, Joe Perches wrote:
> On Thu, 2016-04-21 at 21:28 +0800, Yingjoe Chen wrote:

> > 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.

> []

> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl

> []

> > @@ -2600,6 +2600,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*\bdefault\b\s*n\s*$/) {

> 

> maybe line =~ /^\+\s*default\s+n/i



This might match

	default NIOS2

also this won't match lines with comment.
Will change to  $line =~ /^\+\s*default\s*n\s*(#.*|$)/i


> Also, there are some oddities like:

> 

> arch/mips/cavium-octeon/Kconfig:        default "n"



I think this belong to another (new) test: If an option is bool or
tristate, the default value shouldn't be " quoted.


> and a dozen or so uses like

> 

> 	default n if <foo>

> 


I'm not sure about this. With if, it did provide more information.
According to Documentation/kbuild/kconfig-language.txt:
" A config option can have any number of default values. If multiple
  default values are visible, only the first defined one is active."
So the following example will be different when the first one is
removed.

	default n if <foo>
	default y if <bar>

of course we could do the following, but one could argue the above one
is more readable.

	default y if <bar> && ! <foo>

Joe.C
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d574d13..1c43dc1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2600,6 +2600,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*\bdefault\b\s*n\s*$/) {
+			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;