From: Julian Braha <julianbraha@gmail.com>
To: nathan@kernel.org, nsc@kernel.org, kees@kernel.org
Cc: xry111@xry111.site, hyc.lee@gmail.com, jeffbai@aosc.io,
vegard.nossum@oracle.com, rdunlap@infradead.org,
grahamr@qti.qualcomm.com, nico@fluxnic.net, masahiroy@kernel.org,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
Julian Braha <julianbraha@gmail.com>
Subject: [PATCH] kconfig: fix submenu rendering of negative dependencies
Date: Tue, 21 Jul 2026 20:30:28 +0100 [thread overview]
Message-ID: <20260721193028.313342-1-julianbraha@gmail.com> (raw)
This fixes the "ironic visualization" issue reported here:
https://lore.kernel.org/linux-kbuild/cbe95c15d2760f6fce8eaf207c969ce8fd3703aa.camel@xry111.site/
where a config option FOO is nested in the submenu of the previous option
BAR, despite FOO actually depending on !BAR.
I've only tested locally on x86, but as far as I can tell, this only
changes how 2 options are rendered in the menu:
1. NTFS3_FS, no longer in the NTFS_FS submenu, and
2. MTD_BLOCK_RO, no longer in the MTD_BLOCK submenu.
Assisted-by: Claude:claude-4.8-opus
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
scripts/kconfig/expr.c | 33 +++++++++++++++++++++++++++++++++
scripts/kconfig/expr.h | 1 +
| 10 ++++++++++
3 files changed, 44 insertions(+)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 16f92c4a775a..2b91d16bf14f 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -738,6 +738,39 @@ bool expr_contains_symbol(struct expr *dep, struct symbol *sym)
return false;
}
+/*
+ * Check if the expression references 'sym' in a way that is satisfiable
+ * with 'sym' disabled, e.g.'sym!=y'.
+ *
+ * Expects that expr_transform() was already called on 'expr'.
+ */
+bool expr_contains_symbol_negated(struct expr *dep, struct symbol *sym)
+{
+ if (!dep)
+ return false;
+
+ switch (dep->type) {
+ case E_AND:
+ case E_OR:
+ return expr_contains_symbol_negated(dep->left.expr, sym) ||
+ expr_contains_symbol_negated(dep->right.expr, sym);
+ case E_NOT:
+ return dep->left.expr->type == E_SYMBOL &&
+ dep->left.expr->left.sym == sym;
+ case E_EQUAL:
+ /* sym=n */
+ return dep->left.sym == sym && dep->right.sym == &symbol_no;
+ case E_UNEQUAL:
+ /* sym!=y, sym!=m */
+ return dep->left.sym == sym &&
+ (dep->right.sym == &symbol_yes ||
+ dep->right.sym == &symbol_mod);
+ default:
+ break;
+ }
+ return false;
+}
+
bool expr_depends_symbol(struct expr *dep, struct symbol *sym)
{
if (!dep)
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index fa3823a97d72..b580f9fa0f29 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -307,6 +307,7 @@ tristate expr_calc_value(struct expr *e);
struct expr *expr_eliminate_dups(struct expr *e);
struct expr *expr_transform(struct expr *e);
bool expr_contains_symbol(struct expr *dep, struct symbol *sym);
+bool expr_contains_symbol_negated(struct expr *dep, struct symbol *sym);
bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
--git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index b2d8d4e11e07..9c079e92a9ed 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -428,9 +428,19 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
if (!expr_contains_symbol(dep, sym))
/* No dependency, quit */
break;
+ /*
+ * Note that it's actually possible to depend on both
+ * 'SYM!=y' and 'SYM=y', so we need to first check if
+ * it's a positive dependency before checking if it's
+ * a negative dependency. See example:
+ * 'SFC && MTD && !(SFC=y && MTD=m)'
+ */
if (expr_depends_symbol(dep, sym))
/* Absolute dependency, put in submenu */
goto next;
+ if (expr_contains_symbol_negated(dep, sym))
+ /* Negative dependency, quit */
+ break;
/*
* Also consider it a dependency on sym if our
--
2.54.0
next reply other threads:[~2026-07-21 19:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 19:30 Julian Braha [this message]
2026-07-31 1:00 ` [PATCH] kconfig: fix submenu rendering of negative dependencies Nathan Chancellor
2026-07-31 9:35 ` Julian Braha
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=20260721193028.313342-1-julianbraha@gmail.com \
--to=julianbraha@gmail.com \
--cc=grahamr@qti.qualcomm.com \
--cc=hyc.lee@gmail.com \
--cc=jeffbai@aosc.io \
--cc=kees@kernel.org \
--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 \
--cc=vegard.nossum@oracle.com \
--cc=xry111@xry111.site \
/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