checkpatch: warn on uppercase N/Y/M as Kconfig tristate literals
PATCH 1/1 checkpatch: warn on uppercase N/Y/M as Kconfig tristate literals
Kconfig tristate literals are always lowercase ('n', 'y', 'm') and uppercase N/Y/M are not Kconfig reserved words. Since undefined symbols evaluate to 'n', writing 'default Y' or 'default M' silently produces 'n' instead of 'y'/'m'. 'default N' happens to produce the right value but is still invalid syntax.
Add a warning for N/Y/M in Kconfig expressions found by following the same preprocessing logic used by the Kconfig parser itself.
This new warning was inspired by work done for [1].
---
Fixes such as [2] have already been posted for a few uses.
[2] https://lore.kernel.org/lkml/[email protected]/
scripts/checkpatch.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
scripts/checkpatch.pl +15 -0
@@ -3732,6 +3732,21 @@ sub process { } } +# check for uppercase N/Y/M used as Kconfig tristate literals + if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*(?:default|def_bool|def_tristate|select|imply|depends\s+on|visible\s+if|range|if)\s+(.+)$/) { + my $expr = $1; + $expr =~ s/#.*//; # strip inline comments + $expr =~ s/\$\(.*\)//g; # strip $(macro) expansions + $expr =~ s/"[^"]*"//g; # strip "quoted strings" + $expr =~ s/'[^']*'//g; # strip 'quoted strings' + for my $tok (split /[^A-Za-z0-9_]+/, $expr) { + next unless ($tok eq 'Y' || $tok eq 'M' || $tok eq 'N'); + WARN("KCONFIG_TRISTATE_UPPERCASE", + "'$tok' is probably not what you want here; Kconfig tristate literals are always lowercase ('n', 'y', 'm')\n" . $herecurr); + } + } + # check MAINTAINERS entries if ($realfile =~ /^MAINTAINERS$/) { # check MAINTAINERS entries for the right form
Signature · 1 line
2.43.0
Quoted 10 lines · Andrew Jones
Kconfigtristate literals are always lowercase ('n', 'y', 'm') and uppercase N/Y/M are notKconfigreserved words. Since undefined symbols evaluate to 'n', writing 'default Y' or 'default M' silently produces 'n' instead of 'y'/'m'. 'default N' happens to produce the right value but is still invalid syntax.Add a warning for N/Y/M in
Kconfigexpressions found by following the same preprocessing logic used by theKconfigparser itself.This new warning was inspired by work done for [1].
Signature · 2 lines
With Best Regards, Andy Shevchenko