kconfig: add kconfig-sym-check static checker
PATCH 1/1 kconfig: add kconfig-sym-check static checker
Add 'make kconfig-sym-check', a static checker that finds Kconfig symbols referenced in expressions (select, depends on, default, etc.) but never defined via config/menuconfig anywhere in the tree. New dangling symbols are reported as errors (exit 1) unless they are listed in an exclusion file, e.g.
KCONFIG_SYM_CHECK_EXCLUDES=sym-check-excludes make kconfig-sym-check
The checker also warns about uppercase N/Y/M used as tristate literal values following the same logic as checkpatch.
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
--- Makefile | 7 ++- scripts/kconfig/kconfig-sym-check.pl | 93 ++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 scripts/kconfig/kconfig-sym-check.pl
Makefile +6 -1
@@ -293,6 +293,7 @@ version_h := include/generated/uapi/linux/version.h clean-targets := %clean mrproper cleandocs no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ + kconfig-sym-check \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ outputmakefile rustavailable rustfmt rustfmtcheck \
@@ -1806,6 +1807,7 @@ help: @echo ' includecheck - Check for duplicate included header files' @echo ' headerdep - Detect inclusion cycles in headers' @echo ' coccicheck - Check with Coccinelle' + @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' @echo ' clang-analyzer - Check with clang static analyzer' @echo ' clang-tidy - Check with clang-tidy' @echo ''
@@ -2227,7 +2229,7 @@ endif # Scripts to check various things for consistency # --------------------------------------------------------------------------- -PHONY += includecheck versioncheck coccicheck +PHONY += includecheck versioncheck coccicheck kconfig-sym-check includecheck: find $(srctree)/* $(RCS_FIND_IGNORE) \
@@ -2242,6 +2244,9 @@ versioncheck: coccicheck: $(Q)$(BASH) $(srctree)/scripts/$@ +kconfig-sym-check: + $(Q)cd $(srctree) && $(PERL) scripts/kconfig/kconfig-sym-check.pl $(KCONFIG_SYM_CHECK_EXCLUDES) + PHONY += checkstack kernelrelease kernelversion image_name # UML needs a little special treatment here. It wants to use the host
scripts/kconfig/kconfig-sym-check.pl new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.43.0
+Cc: Randy: FYI.
Quoted 6 lines · Andrew Jones
Add 'make kconfig-sym-check', a static checker that finds
Kconfigsymbols referenced in expressions (select, depends on, default, etc.) but never defined via config/menuconfig anywhere in the tree. New dangling symbols are reported as errors (exit 1) unless they are listed in an exclusion file, e.g.
Quoted 7 lines
KCONFIG_SYM_CHECK_EXCLUDES=sym-check-excludes make kconfig-sym-check
The checker also warns about uppercase N/Y/M used as tristate literal values following the same logic as checkpatch.
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Andrew Jones
Add 'make kconfig-sym-check', a static checker that finds
Kconfigsymbols referenced in expressions (select, depends on, default, etc.) but never defined via config/menuconfig anywhere in the tree. New dangling symbols are reported as errors (exit 1) unless they are listed in an exclusion file, e.g.KCONFIG_SYM_CHECK_EXCLUDES=sym-check-excludes make kconfig-sym-check
The checker also warns about uppercase N/Y/M used as tristate literal values following the same logic as checkpatch.
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Quoted 7 lines
Signed-off-by Andrew Jones <[email protected]>--- Makefile | 7 ++- scripts/kconfig/kconfig-sym-check.pl | 93 ++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 scripts/kconfig/kconfig-sym-check.pl
Thanks.
Signature · 1 line
~Randy
Nathan Chancellor
maintainerOn Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
Hi Andrew,
Quoted 7 lines
[...]
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Signed-off-by Andrew Jones <[email protected]>
I think something like this is reasonable, as least until kconfirm is potentially ready for integration into the tree.
https://lore.kernel.org/[email protected]/
That said, I don't know perl, so some superficial comments to follow.
Makefile versioncheck: · line 2246
Quoted 12 lines
Makefile +2
-0@@ -2240,6 +2242,9 @@ versioncheck: coccicheck: $(Q)$(BASH) $(srctree)/scripts/$@ +kconfig-sym-check: + $(Q)cd $(srctree) && $(PERL) scripts/kconfig/kconfig-sym-check.pl $(KCONFIG_SYM_CHECK_EXCLUDES)
I would prefer to avoid the 'cd $(srctree)' here.
Quoted 7 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0
scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;
What happens if you run this command on a release tarball? We should probably use something like
find $(srctree) -name '*Kconfig*'
here, which would avoid needing the 'cd $(srctree)' above (although kconfig-sym-check.pl would need to be prefixed with $(srctree)/ to ensure the path is valid).
Sashiko has some additional comments that may be relevant, if you have not already seen them.
https://sashiko.dev/#/patchset/19870
Signature · 2 lines
Cheers, Nathan
Quoted 57 lines · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
Hi Andrew,
Quoted 7 lines
[...]
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Signed-off-by Andrew Jones <[email protected]>I think something like this is reasonable, as least until kconfirm is potentially ready for integration into the tree.
https://lore.kernel.org/[email protected]/
That said, I don't know perl, so some superficial comments to follow.
Makefile versioncheck: · line 2246
Quoted 12 lines
Makefile +2
-0@@ -2240,6 +2242,9 @@ versioncheck: coccicheck: $(Q)$(BASH) $(srctree)/scripts/$@ +kconfig-sym-check: + $(Q)cd $(srctree) && $(PERL) scripts/kconfig/kconfig-sym-check.pl $(KCONFIG_SYM_CHECK_EXCLUDES)I would prefer to avoid the 'cd $(srctree)' here.
Quoted 7 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;What happens if you run this command on a release tarball? We should probably use something like
find $(srctree) -name '*Kconfig*'
Quoted 8 lines
here, which would avoid needing the 'cd $(srctree)' above (although kconfig-sym-check.pl would need to be prefixed with $(srctree)/ to ensure the path is valid).
Sashiko has some additional comments that may be relevant, if you have not already seen them.
Thanks, Nathan. I'll make some improvements based on your and Sashiko's comments and send a v2.
drew
Julian Braha
reviewerQuoted 9 lines · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
Hi Andrew,
Quoted 5 lines
[...]
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Andrew Jones <[email protected]>I think something like this is reasonable, as least until kconfirm is potentially ready for integration into the tree.
Agreed, don't let kconfirm block this. While I do have future plans to support these same alarms in that tool, there's currently no overlap between these two, and no ETA on that support either ;)
Side note, this script was actually part of my inspiration to go searching for more misusage of kconfig and build kconfirm. I also previously cleaned up some dead code, thanks to this script:
https://lore.kernel.org/all/[email protected]/
- Julian Braha
Nathan Chancellor
maintainerQuoted 18 lines · Julian Braha
Quoted 9 lines · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
Hi Andrew,
Quoted 5 lines
[...]
This new static checker is the script used for [1] with a few improvements to avoid some false positives.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Andrew Jones <[email protected]>I think something like this is reasonable, as least until kconfirm is potentially ready for integration into the tree.
Quoted 8 lines
Agreed, don't let kconfirm block this. While I do have future plans to support these same alarms in that tool, there's currently no overlap between these two, and no ETA on that support either ;)
Side note, this script was actually part of my inspiration to go searching for more misusage of kconfig and build kconfirm. I also previously cleaned up some dead code, thanks to this script:
https://lore.kernel.org/all/[email protected]/
Thanks a lot for that additional context, especially around the lack of overlap between the two tools. This seems worth pursuing then.
Signature · 2 lines
Cheers, Nathan
Nicolas Schier
maintainerQuoted 1 line · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
[...]
Quoted 21 lines
Quoted 7 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;What happens if you run this command on a release tarball? We should probably use something like
Quoted 1 line
find $(srctree) -name '*Kconfig*'
not fully related, but that reminds me to this thread:
https://lore.kernel.org/linux-kbuild/CAK7LNATJ-3JQ0QQGQ5R+R8aBJEq-tmBL8iBZrbM_4t0zeoYTaw@mail.gmail.com/#r
Signature · 1 line
Nicolas
Nathan Chancellor
maintainerQuoted 24 lines · Nicolas Schier
Quoted 1 line · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
[...]
Quoted 21 lines
Quoted 7 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;What happens if you run this command on a release tarball? We should probably use something like
Quoted 4 lines
Quoted 1 line
find $(srctree) -name '*Kconfig*'not fully related, but that reminds me to this thread:
https://lore.kernel.org/linux-kbuild/CAK7LNATJ-3JQ0QQGQ5R+R8aBJEq-tmBL8iBZrbM_4t0zeoYTaw@mail.gmail.com/#r
Ah yeah, that is definitely worth keeping in mind for the future. I feel like 'find' is not "more complicated" than 'git ls-files' in this case, so I will assume that such an objection would not really hold here (especially since it would help people with development of fresh Kconfig files that have not been committed yet). If we did want to rely on 'git ls-files', we should at least error gracefully if we are not in a git checkout.
Signature · 2 lines
Cheers, Nathan
Quoted 3 lines · Nathan Chancellor
Quoted 2 lines · Nicolas Schier
Quoted 1 line · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
[...]
Quoted 25 lines
Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;What happens if you run this command on a release tarball? We should probably use something like
Quoted 4 lines
Quoted 1 line
find $(srctree) -name '*Kconfig*'not fully related, but that reminds me to this thread:
https://lore.kernel.org/linux-kbuild/CAK7LNATJ-3JQ0QQGQ5R+R8aBJEq-tmBL8iBZrbM_4t0zeoYTaw@mail.gmail.com/#r
Quoted 7 lines
Ah yeah, that is definitely worth keeping in mind for the future. I feel like 'find' is not "more complicated" than 'git ls-files' in this case, so I will assume that such an objection would not really hold here (especially since it would help people with development of fresh
Kconfigfiles that have not been committed yet). If we did want to rely on 'git ls-files', we should at least error gracefully if we are not in a git checkout.
Can we do both depending on the environment (if we are in Git, do that, otherwise fallback to find)? find uses FS, while Git uses index, which is much faster.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nathan Chancellor
maintainerQuoted 40 lines · Andy Shevchenko
Quoted 3 lines · Nathan Chancellor
Quoted 2 lines · Nicolas Schier
Quoted 1 line · Nathan Chancellor
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <[email protected]> wrote:
[...]
Quoted 25 lines
Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
scripts/kconfig/kconfig-sym-check.pl new file +0
-0scripts/kconfig/kconfig-sym-check.pl line 10
Quoted 10 lines
scripts/kconfig/kconfig-sym-check.pl new file +10
-0@@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $kconfig_sym_check_excludes = undef; +$kconfig_sym_check_excludes = $ARGV[0] if (defined $ARGV[0]); + +my @files = `git ls-files '*Kconfig*'`;What happens if you run this command on a release tarball? We should probably use something like
Quoted 4 lines
Quoted 1 line
find $(srctree) -name '*Kconfig*'not fully related, but that reminds me to this thread:
https://lore.kernel.org/linux-kbuild/CAK7LNATJ-3JQ0QQGQ5R+R8aBJEq-tmBL8iBZrbM_4t0zeoYTaw@mail.gmail.com/#rQuoted 7 lines
Ah yeah, that is definitely worth keeping in mind for the future. I feel like 'find' is not "more complicated" than 'git ls-files' in this case, so I will assume that such an objection would not really hold here (especially since it would help people with development of fresh
Kconfigfiles that have not been committed yet). If we did want to rely on 'git ls-files', we should at least error gracefully if we are not in a git checkout.
Quoted 3 lines
Can we do both depending on the environment (if we are in Git, do that, otherwise fallback to
find)?finduses FS, while Git uses index, which is much faster.
It feels like that starts to get into the complicated territory for little gain, considering there is indeed a performance difference but I am not sure that it is an obvious one in the grand scheme of things.
$ hyperfine 'git ls-files "*Kconfig*"' 'find . -name "*Kconfig*"'
Benchmark 1: git ls-files "*Kconfig*"
Time (mean ± σ): 24.6 ms ± 1.0 ms [User: 18.0 ms, System: 6.1 ms]
Range (min … max): 20.5 ms … 28.7 ms 120 runsBenchmark 2: find . -name "*Kconfig*"
Time (mean ± σ): 222.9 ms ± 4.5 ms [User: 80.6 ms, System: 140.1 ms]
Range (min … max): 216.0 ms … 227.6 ms 13 runs Summary
git ls-files "*Kconfig*" ran
9.06 ± 0.43 times faster than find . -name "*Kconfig*"
But I don't know how complicated such checking is in Perl, so I would be willing to see what it looks like.
Signature · 2 lines
Cheers, Nathan
Quoted 3 lines · Nathan Chancellor
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Nathan Chancellor
On Fri, May 15, 2026 at 09:08:07PM +0200, Nicolas Schier wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Ah yeah, that is definitely worth keeping in mind for the future. I feel like 'find' is not "more complicated" than 'git ls-files' in this case, so I will assume that such an objection would not really hold here (especially since it would help people with development of fresh
Kconfigfiles that have not been committed yet). If we did want to rely on 'git ls-files', we should at least error gracefully if we are not in a git checkout.
Quoted 6 lines
Quoted 3 lines
Can we do both depending on the environment (if we are in Git, do that, otherwise fallback to
find)?finduses FS, while Git uses index, which is much faster.It feels like that starts to get into the complicated territory for little gain, considering there is indeed a performance difference
I tend to agree, but it depends on how complicated the things really are if implementing both.
Quoted 4 lines
but I
am not sure that it is an obvious one in the grand scheme of things.$ hyperfine 'git ls-files "*Kconfig*"' 'find . -name "*Kconfig*"'
Does this makes caches cold before *each* attempt?
Quoted 8 lines
Benchmark 1: git ls-files "*Kconfig*"
Time (mean ± σ): 24.6 ms ± 1.0 ms [User: 18.0 ms, System: 6.1 ms] Range (min … max): 20.5 ms … 28.7 ms 120 runsBenchmark 2: find . -name "*Kconfig*"
Time (mean ± σ): 222.9 ms ± 4.5 ms [User: 80.6 ms, System: 140.1 ms] Range (min … max): 216.0 ms … 227.6 ms 13 runs
Quoted 6 lines
Summary
git ls-files "*Kconfig*" ran
9.06 ± 0.43 times faster than find . -name "*Kconfig*"But I don't know how complicated such checking is in Perl, so I would be willing to see what it looks like.
1. Call git ls-files,
2. if the above fails, call find.
3. find never fails (okay... :-)
In any language it shouldn't be much code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nathan Chancellor
maintainerQuoted 7 lines · Andy Shevchenko
Quoted 4 lines · Nathan Chancellor
but I
am not sure that it is an obvious one in the grand scheme of things.$ hyperfine 'git ls-files "*Kconfig*"' 'find . -name "*Kconfig*"'Does this makes caches cold before *each* attempt?
No but if I do so via the '--prepare' option, I see a similar difference.
Quoted 12 lines
Quoted 12 lines
Benchmark 1: git ls-files "*Kconfig*"
Time (mean ± σ): 24.6 ms ± 1.0 ms [User: 18.0 ms, System: 6.1 ms] Range (min … max): 20.5 ms … 28.7 ms 120 runsBenchmark 2: find . -name "*Kconfig*"
Time (mean ± σ): 222.9 ms ± 4.5 ms [User: 80.6 ms, System: 140.1 ms] Range (min … max): 216.0 ms … 227.6 ms 13 runsSummary
git ls-files "*Kconfig*" ran
9.06 ± 0.43 times faster than find . -name "*Kconfig*"
Quoted 8 lines
Quoted 2 lines
But I don't know how complicated such checking is in Perl, so I would be willing to see what it looks like.
1. Call
git ls-files,
2. if the above fails, callfind.
3.findnever fails (okay... :-)In any language it shouldn't be much code.
Yeah, I guess I would look for '.git' before calling 'git ls-files' but that should work as well. It's up to Andrew.
Signature · 2 lines
Cheers, Nathan