Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Julian Braha <julianbraha@gmail.com>
Cc: nathan@kernel.org, nsc@kernel.org, rdunlap@infradead.org,
	masahiroy@kernel.org, grahamr@qti.qualcomm.com, nico@fluxnic.net,
	linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org
Subject: Re: [PATCH] kconfig: warn on dead default
Date: Sat, 6 Jun 2026 16:23:26 +0200	[thread overview]
Message-ID: <20260606142326.GA117482@ravnborg.org> (raw)
In-Reply-To: <20260606140008.271929-1-julianbraha@gmail.com>

Hi Julian.

On Sat, Jun 06, 2026 at 03:00:08PM +0100, Julian Braha wrote:
> The dead default check was originally introduced with kconfirm:
> https://lore.kernel.org/all/6ec4df6d-1445-48ca-8f54-1d1a83c4716d@gmail.com/
> 
> While I'm still working on that tool, it's not yet ready for inclusion
> into the tree. I am currently waiting for common distro packagers to
> package the parsing library before submitting the next RFC iteration.
> 
> However, the dead default check is more impactful than the other checks:
> all 4 dead defaults that were detected should not have been dead and could
> cause misconfiguration bugs. But fortunately, these were just for kunit
> tests. The 3 patches to fix them have all since been merged:
> commit aef656a0e6c0 ("powerpc: fix dead default for GUEST_STATE_BUFFER_TEST")
> commit 30cc5e2ad826 ("s390/Kconfig: Cleanup defaults for selftests")
> commit df75430515c3 ("drm: fix dead default for DRM_TTM_KUNIT_TEST")
> 
> We can actually check for dead defaults while evaluating Kconfig, which
> should be even more effective at preventing future instances than keeping
> it in a static checker.
> 
> Note that this patch will only trigger a warning when the default values
> are different, in other words, pure duplicate defaults won't cause a
> warning, as they are simply redundant.

A drive-by comment below.

> 
> Signed-off-by: Julian Braha <julianbraha@gmail.com>
> ---
>  scripts/kconfig/menu.c                        | 22 +++++++++-
>  .../kconfig/tests/warn_dead_default/Kconfig   | 40 +++++++++++++++++++
>  .../tests/warn_dead_default/__init__.py       |  8 ++++
>  .../tests/warn_dead_default/expected_stderr   |  4 ++
>  4 files changed, 73 insertions(+), 1 deletion(-)
>  create mode 100644 scripts/kconfig/tests/warn_dead_default/Kconfig
>  create mode 100644 scripts/kconfig/tests/warn_dead_default/__init__.py
>  create mode 100644 scripts/kconfig/tests/warn_dead_default/expected_stderr
> 
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index b2d8d4e11e07..8c280292f9cd 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -242,13 +242,33 @@ static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
>  
>  static void sym_check_prop(struct symbol *sym)
>  {
> -	struct property *prop;
> +	struct property *prev, *prop;
>  	struct symbol *sym2;
>  	char *use;
>  
>  	for (prop = sym->prop; prop; prop = prop->next) {
This part iterates through all properties of sym.
>  		switch (prop->type) {
>  		case P_DEFAULT:
> +			for_all_defaults(sym, prev) {
And this part iterates through all properties of sym and will match only
P_DEFAULT.

I looks redundant with the two loops were we for the latter knows it is
a P_DEFAULT.

> +				if (prev == prop)
> +					break;
> +				if (expr_is_yes(prev->visible.expr)) {
> +					if (!expr_eq(prev->expr, prop->expr))
> +						prop_warn(prop,
> +							"default for '%s' is unreachable: earlier default at %s:%d is unconditional",
> +							sym->name ? sym->name : "<choice>",
> +							prev->filename, prev->lineno);
> +					break;
> +				}
> +				if (expr_eq(prev->visible.expr, prop->visible.expr)) {
> +					if (!expr_eq(prev->expr, prop->expr))
> +						prop_warn(prop,
> +							"default for '%s' has the same condition as the earlier default at %s:%d",
> +							sym->name ? sym->name : "<choice>",
> +							prev->filename, prev->lineno);
> +					break;
> +				}
> +			}
>  			if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
>  			    prop->expr->type != E_SYMBOL)
>  				prop_warn(prop,

	Sam

  reply	other threads:[~2026-06-06 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-06 14:00 [PATCH] kconfig: warn on dead default Julian Braha
2026-06-06 14:23 ` Sam Ravnborg [this message]
2026-06-06 15:01   ` Julian Braha
2026-06-06 17:36     ` Sam Ravnborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260606142326.GA117482@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=grahamr@qti.qualcomm.com \
    --cc=julianbraha@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nico@fluxnic.net \
    --cc=nsc@kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox