Skip to contentSkip to conversation

kconfig: fix submenu rendering of negative dependencies

PATCH Superseded Julian Braha 2 participants 3 messages Jul 21 – Jul 31

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Julian Braha

author reviewer
#0 lore raw

PATCH 1/1 kconfig: fix submenu rendering of negative dependencies

This fixes the "ironic visualization" issue reported here:
https://lore.kernel.org/linux-kbuild/[email protected]/

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
---
 scripts/kconfig/expr.c | 33 +++++++++++++++++++++++++++++++++
 scripts/kconfig/expr.h |  1 +
 scripts/kconfig/menu.c | 10 ++++++++++
 3 files changed, 44 insertions(+)
scripts/kconfig/expr.c +33 -0
index 16f92c4a775a..2b91d16bf14f 100644
@@ -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)
scripts/kconfig/expr.h +1 -0
index fa3823a97d72..b580f9fa0f29 100644
@@ -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);
 
scripts/kconfig/menu.c +10 -0
index b2d8d4e11e07..9c079e92a9ed 100644
@@ -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
Signature · 1 line
2.54.0
maintainer Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines

This fixes the "ironic visualization" issue reported here:
https://lore.kernel.org/linux-kbuild/[email protected]/

where a config option FOO is nested in the submenu of the previous option BAR, despite FOO actually depending on !BAR.

I would prefer to have a short standalone blurb about the issue reported at that link so that the commit message is self-contained. Move the link to the trailers with the Closes: tag.

Quoted 4 lines

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.

These both seem like correct changes from what I can tell.

Quoted 2 lines
Assisted-by Claude:claude-4.8-opus
Quoted 5 lines
scripts/kconfig/expr.c +0 -0
index 16f92c4a775a..2b91d16bf14f 100644

scripts/kconfig/expr.c bool expr_contains_symbol(struct expr *dep, struct symbol *sym) · line 747

Quoted 10 lines
scripts/kconfig/expr.c +7 -0
@@ -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)

I get that this mostly mirrors expr_contains_symbol() but I am not sure I love the name since the symbol might not actually be negated. That said, I don't really have a better suggestion :/

Signature · 2 lines
Cheers,
Nathan
author reviewer
#2 lore raw

Hi Nathan,

Quoted 3 lines · Nathan Chancellor

I would prefer to have a short standalone blurb about the issue reported at that link so that the commit message is self-contained. Move the link to the trailers with the Closes: tag.

Thank you for reviewing, will send a v2 with this change.

- Julian Braha