[PATCH] kconfig: add kconfig-sym-check static checker

Andrew Jones posted 1 patch 4 weeks, 1 day ago
There is a newer version of this series
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
[PATCH] kconfig: add kconfig-sym-check static checker
Posted by Andrew Jones 4 weeks, 1 day ago
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.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 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

diff --git a/Makefile b/Makefile
index fc2d94aafb45..5a0a9f9d6169 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
new file mode 100755
index 000000000000..a6907e585962
--- /dev/null
+++ b/scripts/kconfig/kconfig-sym-check.pl
@@ -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*'`;
+my %configs = ();
+my %refs = ();
+
+foreach my $file (<@files>) {
+	open F, $file or die "Cannot open $file: $!";
+
+	my $help = 0;
+	my $help_level;
+	my $level;
+
+	while (<F>) {
+		chomp;
+
+		next if /^\s*$/;
+		next if /^\s*#/;
+
+		/^(\s*)/;
+		$level = length $1;
+
+		if ($help && $level < $help_level) {
+			$help = 0;
+		}
+
+		next if ($help);
+
+		if (/^\s*(help|\-\-\-help\-\-\-)$/) {
+			$help = 1;
+			$_ = <F>;
+			/^(\s*)/;
+			$help_level = length $1;
+			next;
+		}
+
+		if (/^\s*(config|menuconfig)\s+([a-zA-Z0-9_]+)\s*(#.*)?$/) {
+			$configs{$2}++;
+			next;
+		}
+
+		my $comment_idx = index $_, "#";
+		if ($comment_idx != -1) {
+			$_ = substr $_, 0, $comment_idx;
+		}
+
+		if (/^\s*(default|def_bool|def_tristate|select|depends\s+on|imply|visible\s+if|range|if)\s+(.+)\s*$/) {
+			my $s = $2;
+			$s =~ s/\$\(.*\)//g;
+			$s =~ s/'[^']*'//g;
+			$s =~ s/"[^"]*"//g;
+			$s =~ s/%%[^%]*%%//g;
+			my @syms = split /[^a-zA-Z0-9_]+/, $s;
+			map {
+				$refs{$_}++ if (/[a-zA-Z]/ && $_ ne "if" && $_ ne "y" && $_ ne "n" && $_ ne "m" && !(/^0[xX]/ && !/[g-wy-zG-WY-Z]/));
+			} @syms
+		}
+	}
+
+	close F;
+}
+
+my %known_syms = ();
+if (defined $kconfig_sym_check_excludes) {
+	my $file = $kconfig_sym_check_excludes;
+	open F, $file or die "Cannot open $file: $!";
+	while (<F>) {
+		chomp;
+		next if /^\s*$/;
+		next if /^\s*#/;
+		$known_syms{$1}++ if (/^\s*([a-zA-Z0-9_]+)\s*(#.*)?$/);
+	}
+}
+
+my $ret = 0;
+foreach my $k (sort keys %refs) {
+	next if (exists $configs{$k} || exists $known_syms{$k});
+
+	print "$k";
+	print " - warning: '$k' is probably not what you want; Kconfig tristate literals are always lowercase ('n', 'y', 'm')" if ($k eq "N" || $k eq "Y" || $k eq "M");
+	print "\n";
+
+	$ret = 1;
+}
+
+exit $ret;
-- 
2.43.0
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Nathan Chancellor 4 weeks, 1 day ago
On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:

Hi Andrew,

> [...]
> 
> This new static checker is the script used for [1] with a few
> improvements to avoid some false positives.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>

I think something like this is reasonable, as least until kconfirm
is potentially ready for integration into the tree.

  https://lore.kernel.org/20260509203808.1142311-1-julianbraha@gmail.com/

That said, I don't know perl, so some superficial comments to follow.

>
>
> diff --git a/Makefile b/Makefile
> index e27c91ea56fc..75487383805b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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.

>
> diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> new file mode 100755
> index 000000000000..a6907e585962
> --- /dev/null
> +++ b/scripts/kconfig/kconfig-sym-check.pl
> @@ -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

-- 
Cheers,
Nathan
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Nicolas Schier 3 weeks, 6 days ago
On Thu, May 14, 2026 at 10:32:12PM +0900, Nathan Chancellor wrote:
> On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
[...]
> >
> > diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> > new file mode 100755
> > index 000000000000..a6907e585962
> > --- /dev/null
> > +++ b/scripts/kconfig/kconfig-sym-check.pl
> > @@ -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*'

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


-- 
Nicolas
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Nathan Chancellor 3 weeks, 5 days ago
On Fri, May 15, 2026 at 09:08:07PM +0200, Nicolas Schier wrote:
> On Thu, May 14, 2026 at 10:32:12PM +0900, Nathan Chancellor wrote:
> > On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
> [...]
> > >
> > > diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> > > new file mode 100755
> > > index 000000000000..a6907e585962
> > > --- /dev/null
> > > +++ b/scripts/kconfig/kconfig-sym-check.pl
> > > @@ -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*'
> 
> 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.

-- 
Cheers,
Nathan
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Andy Shevchenko 3 weeks, 5 days ago
On Sun, May 17, 2026 at 01:26:07PM +0900, Nathan Chancellor wrote:
> On Fri, May 15, 2026 at 09:08:07PM +0200, Nicolas Schier wrote:
> > On Thu, May 14, 2026 at 10:32:12PM +0900, Nathan Chancellor wrote:
> > > On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:

[...]

> > > > diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> > > > new file mode 100755
> > > > index 000000000000..a6907e585962
> > > > --- /dev/null
> > > > +++ b/scripts/kconfig/kconfig-sym-check.pl
> > > > @@ -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*'
> > 
> > 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.

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.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Nathan Chancellor 3 weeks, 5 days ago
On Sun, May 17, 2026 at 09:14:47AM +0300, Andy Shevchenko wrote:
> On Sun, May 17, 2026 at 01:26:07PM +0900, Nathan Chancellor wrote:
> > On Fri, May 15, 2026 at 09:08:07PM +0200, Nicolas Schier wrote:
> > > On Thu, May 14, 2026 at 10:32:12PM +0900, Nathan Chancellor wrote:
> > > > On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
> 
> [...]
> 
> > > > > diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> > > > > new file mode 100755
> > > > > index 000000000000..a6907e585962
> > > > > --- /dev/null
> > > > > +++ b/scripts/kconfig/kconfig-sym-check.pl
> > > > > @@ -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*'
> > > 
> > > 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.
> 
> 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.

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 runs

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

-- 
Cheers,
Nathan
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Andy Shevchenko 3 weeks, 5 days ago
On Sun, May 17, 2026 at 06:11:28PM +0900, Nathan Chancellor wrote:
> On Sun, May 17, 2026 at 09:14:47AM +0300, Andy Shevchenko wrote:
> > On Sun, May 17, 2026 at 01:26:07PM +0900, Nathan Chancellor wrote:
> > > On Fri, May 15, 2026 at 09:08:07PM +0200, Nicolas Schier wrote:

[...]

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

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

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

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.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Julian Braha 4 weeks ago
On 5/14/26 14:32, Nathan Chancellor wrote:
> On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
> 
> Hi Andrew,
> 
>> [...]
>>
>> This new static checker is the script used for [1] with a few
>> improvements to avoid some false positives.
>>
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
>> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> 
> I think something like this is reasonable, as least until kconfirm
> is potentially ready for integration into the tree.
> 
>   https://lore.kernel.org/20260509203808.1142311-1-julianbraha@gmail.com/
> 
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/20260309122321.1528622-1-julianbraha@gmail.com/

- Julian Braha
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Nathan Chancellor 4 weeks ago
On Thu, May 14, 2026 at 04:26:42PM +0100, Julian Braha wrote:
> On 5/14/26 14:32, Nathan Chancellor wrote:
> > On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
> > 
> > Hi Andrew,
> > 
> >> [...]
> >>
> >> This new static checker is the script used for [1] with a few
> >> improvements to avoid some false positives.
> >>
> >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
> >> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> > 
> > I think something like this is reasonable, as least until kconfirm
> > is potentially ready for integration into the tree.
> > 
> >   https://lore.kernel.org/20260509203808.1142311-1-julianbraha@gmail.com/
> > 
> 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/20260309122321.1528622-1-julianbraha@gmail.com/

Thanks a lot for that additional context, especially around the lack of
overlap between the two tools. This seems worth pursuing then.

-- 
Cheers,
Nathan
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Andrew Jones 4 weeks, 1 day ago
On Thu, May 14, 2026 at 10:32:12PM +0900, Nathan Chancellor wrote:
> On Wed, 13 May 2026 16:03:29 -0500, Andrew Jones <andrew.jones@linux.dev> wrote:
> 
> Hi Andrew,
> 
> > [...]
> > 
> > This new static checker is the script used for [1] with a few
> > improvements to avoid some false positives.
> > 
> > Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
> > Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> 
> I think something like this is reasonable, as least until kconfirm
> is potentially ready for integration into the tree.
> 
>   https://lore.kernel.org/20260509203808.1142311-1-julianbraha@gmail.com/
> 
> That said, I don't know perl, so some superficial comments to follow.
> 
> >
> >
> > diff --git a/Makefile b/Makefile
> > index e27c91ea56fc..75487383805b 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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.
> 
> >
> > diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl
> > new file mode 100755
> > index 000000000000..a6907e585962
> > --- /dev/null
> > +++ b/scripts/kconfig/kconfig-sym-check.pl
> > @@ -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

Thanks, Nathan. I'll make some improvements based on your and Sashiko's
comments and send a v2.

drew
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Randy Dunlap 4 weeks, 1 day ago

On 5/13/26 2:03 PM, Andrew Jones wrote:
> 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.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1]
> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> ---
>  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

Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>

Thanks.

-- 
~Randy
Re: [PATCH] kconfig: add kconfig-sym-check static checker
Posted by Andy Shevchenko 4 weeks, 1 day ago
+Cc: Randy: FYI.

On Wed, May 13, 2026 at 04:03:29PM -0500, Andrew Jones wrote:
> 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.

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko