Skip to contentSkip to conversation

checkpatch: avoid default n

PATCH In review Miles Chen 3 participants 7 messages Jul 3, 2019 – Jul 4, 2019

Subsystems (2)
lore
Share & tools
lore

Miles Chen

author
#0 lore raw

PATCH 1/1 checkpatch: avoid default n

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)
scripts/checkpatch.pl +7 -0
index 342c7c781ba5..6531b5757c6b 100755
@@ -3005,6 +3005,13 @@ sub process {
 			     "Use of boolean is deprecated, please use bool instead.\n" . $herecurr);
 		}
 
+# avoid redundant 'default n'
+		if ($realfile =~ /Kconfig/ &&
+		    $line =~ /^\+\s*\bdefault n\b/) {
+			WARN("AVOID_DEFAULT_N",
+			     "'default n' is the default value, no need to write it explicitly.\n" . $herecurr);
+		}
+
 		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
 		    ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
 			my $flag = $1;
Signature · 1 line
2.18.0
maintainer
#1 lore raw
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC
#2 lore raw
Quoted 16 lines · Joe Perches
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

Quoted 7 lines

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC

I've sent similar patch in 2016, my version won't complain about these.

https://lkml.org/lkml/2016/4/22/580

Joe.C

#3 lore raw
In reply to Joe Perches
Quoted 16 lines · Joe Perches
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

Quoted 7 lines

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC

Hi,

I've sent similar patch in 2016, my version won't complain about these.

https://lkml.org/lkml/2016/4/22/580

Joe.C

maintainer
#4 lore raw
Quoted 25 lines · Yingjoe Chen
Quoted 16 lines · Joe Perches
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

Quoted 7 lines

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC
Quoted 6 lines

Hi,

I've sent similar patch in 2016, my version won't complain about these.

https://lkml.org/lkml/2016/4/22/580

Hi again.

https://lore.kernel.org/lkml/[email protected]/

I would prefer a generic solution that also handles the quoted use.

$ git grep -P 'default\s*\"[ynm]"' -- '*/Kconfig*'
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/cavium-octeon/Kconfig:        default "n"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
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"

or maybe 2 separate patches.

And the "default y" case and probably the
"default \!?EXPERT" is or should be generally
discouraged. Especially for drivers.

https://lore.kernel.org/lkml/CAHk-=wiZ24JuVehJ5sEC0UG1Gk2nvB363wO02RRsR1oEht6R9Q@mail.gmail.com/

author
#5 lore raw
Quoted 59 lines · Joe Perches
Quoted 25 lines · Yingjoe Chen
Quoted 16 lines · Joe Perches
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think
it might be helpful to add this test in checkpatch. DEFAULT_VALUE_STYLE
tested:
WARNING: 'default n' is the default value, no need to write it explicitly.
+ default n

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

Quoted 7 lines

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC
Quoted 6 lines

Hi,

I've sent similar patch in 2016, my version won't complain about these.

https://lkml.org/lkml/2016/4/22/580

Hi again.

https://lore.kernel.org/lkml/[email protected]/

I would prefer a generic solution that also handles the quoted use.

$ git grep -P 'default\s*\"[ynm]"' -- '*/Kconfig*'
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/Kconfig:      default "y"
arch/mips/cavium-octeon/Kconfig:        default "n"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
arch/mips/cavium-octeon/Kconfig:        default "y"
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"
Quoted 9 lines

or maybe 2 separate patches.

And the "default y" case and probably the
"default \!?EXPERT" is or should be generally
discouraged. Especially for drivers.

https://lore.kernel.org/lkml/CAHk-=wiZ24JuVehJ5sEC0UG1Gk2nvB363wO02RRsR1oEht6R9Q@mail.gmail.com/

Thanks for your comment, I'll send another patch for these cases:
1. default "[ynm]"
2. default \!?EXPERT
3. default n$

author
#6 lore raw
In reply to Joe Perches
Quoted 16 lines · Joe Perches
Quoted 8 lines · Miles Chen

This change reports a warning when "default n" is used.

I have seen several "remove default n" patches, so I think it might be helpful to add this test in checkpatch.

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

I don't think this is reasonable as there are
several uses like:

default y
default n if <foo>

Quoted 9 lines

For instance:

arch/alpha/Kconfig-config ALPHA_WTINT

arch/alpha/Kconfig-     bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
arch/alpha/Kconfig-     default y if ALPHA_QEMU
arch/alpha/Kconfig:     default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA)
arch/alpha/Kconfig:     default n if !ALPHA_SRM && !ALPHA_GENERIC

Thanks for your comment, perhaps we can just deal with the "default n$" case?

like:
+ $line =~ /^\+\s*\bdefault n$/) {