Skip to contentSkip to conversation

kconfig: Avoid prompting for transitional symbols

PATCH Superseded Kees Cook 2 participants 3 messages Sep 30, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kconfig: Avoid prompting for transitional symbols

The "transitional" symbol keyword, while working with the "olddefconfig" target, was prompting during "oldconfig". This occurred because these symbols were not being marked as user-defined when they received values from transitional symbols that had user values. The "olddefconfig" target explicitly doesn't prompt for anything, so this deficiency wasn't noticed.

The issue manifested when a symbol's value came from a transitional symbol's user value but the receiving symbol wasn't marked with SYMBOL_DEF_USER. Thus the "oldconfig" logic would then prompt for these symbols unnecessarily.

Check after value calculation whether a symbol without a user value gets its value from a single transitional symbol that does have a user value. In such cases, mark the receiving symbol as user-defined to prevent prompting.

Update regression tests to verify that symbols with transitional defaults are not prompted in "oldconfig", except when conditional defaults evaluate to 'no' and should legitimately be prompted.

Build tested with "make testconfig".

Fixes 05020835c86e ("kconfig: Add transitional symbol attribute for migration support")
Cc Vegard Nossum <[email protected]>
---
 scripts/kconfig/tests/transitional/Kconfig    | 32 +++++++++++++++++++
 scripts/kconfig/symbol.c                      | 18 ++++++++++-
 .../kconfig/tests/transitional/__init__.py    |  7 ++++
 .../tests/transitional/expected_config        |  3 ++
 .../tests/transitional/expected_stdout        |  1 +
 .../kconfig/tests/transitional/initial_config |  4 +++
 6 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 scripts/kconfig/tests/transitional/expected_stdout
scripts/kconfig/tests/transitional/Kconfig +32 -0
index 62c3b24665b9..faa4d396f828 100644
@@ -96,5 +96,37 @@ config OLD_WITH_HELP
 	help
 	  This transitional symbol has a help section to validate that help is allowed.
 
+# Test that we can set something to =n via transitional symbol
+config NEW_DISABLED
+	tristate "Check for setting to disabled"
+	default OLD_DISABLED
+
+config OLD_DISABLED
+	tristate
+	transitional
+
+# Test that a potential new value disappears if it lacks a prompt
+config NEW_DISABLED_UNSAVED
+	tristate
+	default OLD_DISABLED
+
+config OLD_DISABLED_UNSAVED
+	tristate
+	transitional
+
+# Test conditional default: transitional value should not prevent prompting
+# when default visibility makes the expression evaluate to 'no'
+config DEPENDENCY_TEST
+	bool "Dependency for testing"
+	default n
+
+config NEW_CONDITIONAL_DEFAULT
+	bool "New option with conditional default"
+	default OLD_CONDITIONAL_DEFAULT if DEPENDENCY_TEST
+
+config OLD_CONDITIONAL_DEFAULT
+	bool
+	transitional
+
 config REGULAR_OPTION
 	bool "Regular option"
scripts/kconfig/symbol.c +17 -1
index 760cac998381..9cc2fd5bc016 100644
@@ -411,7 +411,7 @@ bool sym_dep_errors(void)
 void sym_calc_value(struct symbol *sym)
 {
 	struct symbol_value newval, oldval;
-	struct property *prop;
+	struct property *prop = NULL;
 	struct menu *choice_menu;
 
 	if (!sym)
@@ -520,6 +520,22 @@ void sym_calc_value(struct symbol *sym)
 		;
 	}
 
+	/*
+	 * If the symbol lacks a user value but its value comes from a
+	 * single transitional symbol with an existing user value, mark
+	 * this symbol as having a user value to avoid prompting.
+	 */
+	if (prop && !sym_has_value(sym)) {
+		struct symbol *ds = prop_get_symbol(prop);
+		if (ds && (ds->flags & SYMBOL_TRANS) && sym_has_value(ds)) {
+			if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
+				sym->def[S_DEF_USER].tri = newval.tri;
+			else
+				sym->def[S_DEF_USER].val = newval.val;
+			sym->flags |= SYMBOL_DEF_USER;
+		}
+	}
+
 	sym->curr = newval;
 	sym_validate_range(sym);
 
scripts/kconfig/tests/transitional/__init__.py +7 -0
index 61937d10edf1..b50ba2397548 100644
@@ -6,6 +6,7 @@ This tests that:
 - OLD_* options in existing .config cause NEW_* options to be set
 - OLD_* options are not written to the new .config file
 - NEW_* options appear in the new .config file with correct values
+- NEW_* options with defaults from transitional symbols are not prompted
 - All Kconfig types work correctly: bool, tristate, string, hex, int
 - User-set NEW values take precedence over conflicting OLD transitional values
 """
@@ -16,3 +17,9 @@ def test(conf):
 
     # Check that the configuration matches expected output
     assert conf.config_contains('expected_config')
+
+    # Test oldconfig to ensure symbols with transitional defaults are not prompted
+    assert conf.oldconfig(dot_config='initial_config', in_keys='n\n') == 0
+
+    # Except for when conditional default evaluates to 'no'
+    assert conf.stdout_contains('expected_stdout')
scripts/kconfig/tests/transitional/expected_config +3 -0
index 846e9ddcab91..e01f5f070a26 100644
@@ -9,4 +9,7 @@ CONFIG_NEW_STRING_PRECEDENCE="user value"
 CONFIG_NEW_TRISTATE_PRECEDENCE=y
 CONFIG_NEW_HEX_PRECEDENCE=0xABCD
 CONFIG_NEW_INT_PRECEDENCE=100
+# CONFIG_NEW_DISABLED is not set
+# CONFIG_DEPENDENCY_TEST is not set
+# CONFIG_NEW_CONDITIONAL_DEFAULT is not set
 # CONFIG_REGULAR_OPTION is not set
scripts/kconfig/tests/transitional/expected_stdout new file +1 -0
new file mode 100644
index 000000000000..80eadd4e6a8d
@@ -0,0 +1 @@
+New option with conditional default (NEW_CONDITIONAL_DEFAULT) [N/y/?] (NEW)
scripts/kconfig/tests/transitional/initial_config +4 -0
index e648a65e504c..68b7da672426 100644
@@ -14,3 +14,7 @@ CONFIG_NEW_HEX_PRECEDENCE=0xABCD
 CONFIG_OLD_HEX_PRECEDENCE=0x5678
 CONFIG_NEW_INT_PRECEDENCE=100
 CONFIG_OLD_INT_PRECEDENCE=200
+# CONFIG_OLD_DISABLED is not set
+# CONFIG_OLD_DISABLED_UNSAVED is not set
+# CONFIG_DEPENDENCY_TEST is not set
+CONFIG_OLD_CONDITIONAL_DEFAULT=y
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Kees Cook

The "transitional" symbol keyword, while working with the "olddefconfig" target, was prompting during "oldconfig". This occurred because these symbols were not being marked as user-defined when they received values from transitional symbols that had user values. The "olddefconfig" target explicitly doesn't prompt for anything, so this deficiency wasn't noticed.

The issue manifested when a symbol's value came from a transitional symbol's user value but the receiving symbol wasn't marked with SYMBOL_DEF_USER. Thus the "oldconfig" logic would then prompt for these symbols unnecessarily.

Quoted 4 lines

Check after value calculation whether a symbol without a user value gets its value from a single transitional symbol that does have a user value. In such cases, mark the receiving symbol as user-defined to prevent prompting.

Sorry for not catching this issue.

Quoted 19 lines
scripts/kconfig/symbol.c +3 -1
index 760cac998381..9cc2fd5bc016 100644
@@ -411,7 +411,7 @@ bool sym_dep_errors(void)
  void sym_calc_value(struct symbol *sym)
  {
  	struct symbol_value newval, oldval;
-	struct property *prop;
+	struct property *prop = NULL;
  	struct menu *choice_menu;
 
  	if (!sym)
@@ -520,6 +520,22 @@ void sym_calc_value(struct symbol *sym)
  		;
  	}
 
+	/*
+	 * If the symbol lacks a user value but its value comes from a

scripts/kconfig/symbol.c void sym_calc_value(struct symbol *sym) · line 534

Quoted 10 lines
scripts/kconfig/symbol.c +10 -0
+	 * single transitional symbol with an existing user value, mark
+	 * this symbol as having a user value to avoid prompting.
+	 */
+	if (prop && !sym_has_value(sym)) {
+		struct symbol *ds = prop_get_symbol(prop);
+		if (ds && (ds->flags & SYMBOL_TRANS) && sym_has_value(ds)) {
+			if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
+				sym->def[S_DEF_USER].tri = newval.tri;
+			else
+				sym->def[S_DEF_USER].val = newval.val;

sym->def[S_DEF_USER] and newval are both 'struct symbol_value', can we just unconditionally do this instead?

    sym->def[S_DEF_USER] = newval;

scripts/kconfig/symbol.c void sym_calc_value(struct symbol *sym) · line 540

Quoted 6 lines
scripts/kconfig/symbol.c +4 -0
+			sym->flags |= SYMBOL_DEF_USER;
+		}
+	}
+
  	sym->curr = newval;
  	sym_validate_range(sym);

I have to run, will take a closer look later. Thanks,

Vegard

author
#2 lore raw
Quoted 11 lines · Vegard Nossum

scripts/kconfig/symbol.c void sym_calc_value(struct symbol *sym) · line 534

Quoted 5 lines · Kees Cook

[...]

scripts/kconfig/symbol.c +4 -0
+			if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
+				sym->def[S_DEF_USER].tri = newval.tri;
+			else
+				sym->def[S_DEF_USER].val = newval.val;

sym->def[S_DEF_USER] and newval are both 'struct symbol_value', can we just unconditionally do this instead?

    sym->def[S_DEF_USER] = newval;

Argh, yes. I even went and looked at that struct to see if tri and val were a union and my brain didn't get to the next step. :P

I'll update this.

Quoted 1 line

I have to run, will take a closer look later. Thanks,

Thanks!

Signature · 1 line
Kees Cook