Skip to contentSkip to conversation

kconfig: error out for recursive range

PATCH In review Julian Braha 2 participants 3 messages Aug 16 – Sep 1

Subsystems (2)
lore
Share & tools
lore

Julian Braha

author reviewer
#0 lore raw

PATCH 1/1 kconfig: error out for recursive range

Currently, it is possible to create recursive ranges with Kconfig, such as:

config C
int "Enable C"
default 1
range A B

config A
int "Enable A"
default 2
range B C

config B
int "Enable B"
default 3
range A C

The current outcome of this example above, is that all 3 options are set to 2. There is currently no warning or error if a user attempts this.

Several attributes are already checked for recursion, including 'depends on', 'select', and 'imply', and we can extend this to 'range' for numeric options (int and hex types).

Recursive ranges are currently not used anywhere in the tree, so it is already safe to make this a hard error.

Assisted-by Codex:gpt-5.6-sol
---
 scripts/kconfig/symbol.c                      |  5 +++-
 .../kconfig/tests/err_recursive_dep/Kconfig   | 24 +++++++++++++++++++
 .../tests/err_recursive_dep/expected_stderr   | 13 ++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +4 -1
index 7e81b3676ee9..e82f330fb8ee 100644
@@ -1196,6 +1196,7 @@ static struct symbol *sym_check_expr_deps(const struct expr *e)
 	case E_GTH:
 	case E_LEQ:
 	case E_LTH:
+	case E_RANGE:
 	case E_UNEQUAL:
 		sym = sym_check_deps(e->left.sym);
 		if (sym)
@@ -1243,7 +1244,9 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 		sym2 = sym_check_expr_deps(prop->visible.expr);
 		if (sym2)
 			break;
-		if (prop->type != P_DEFAULT || sym_is_choice(sym))
+		if (sym_is_choice(sym))
+			continue;
+		if (prop->type != P_DEFAULT && prop->type != P_RANGE)
 			continue;
 		stack.expr = &prop->expr;
 		sym2 = sym_check_expr_deps(prop->expr);
scripts/kconfig/tests/err_recursive_dep/Kconfig +24 -0
index ebdb3ffd8717..bd1ff92bcab2 100644
@@ -61,3 +61,27 @@ config G
 	bool "G"
 
 endmenu
+
+# depends on and range
+
+config H1
+	int
+	depends on H2 < H3
+
+config H2
+	int
+	range H3 H1
+
+config H3
+	int
+	range H1 H2
+
+# range
+
+config I1
+	int
+	range I2 I2
+
+config I2
+	int
+	range I1 I1
scripts/kconfig/tests/err_recursive_dep/expected_stderr +13 -0
index fc2e860af082..08f843087678 100644
@@ -36,3 +36,16 @@ error: recursive dependency detected!
 	symbol G depends on G
 For a resolution refer to Documentation/kbuild/kconfig-language.rst
 subsection "Kconfig recursive dependency limitations"
+
+error: recursive dependency detected!
+	symbol H1 depends on H2
+	symbol H2 range value contains H3
+	symbol H3 range value contains H1
+For a resolution refer to Documentation/kbuild/kconfig-language.rst
+subsection "Kconfig recursive dependency limitations"
+
+error: recursive dependency detected!
+	symbol I1 range value contains I2
+	symbol I2 range value contains I1
+For a resolution refer to Documentation/kbuild/kconfig-language.rst
+subsection "Kconfig recursive dependency limitations"
Signature · 1 line
2.55.0
#1 lore raw
Quoted 20 lines

Currently, it is possible to create recursive ranges with Kconfig, such as:

config C
int "Enable C"
default 1
range A B

config A
int "Enable A"
default 2
range B C

config B
int "Enable B"
default 3
range A C

The current outcome of this example above, is that all 3 options are set to 2. There is currently no warning or error if a user attempts this.

Quoted 6 lines

Several attributes are already checked for recursion, including 'depends on', 'select', and 'imply', and we can extend this to 'range' for numeric options (int and hex types).

Recursive ranges are currently not used anywhere in the tree, so it is already safe to make this a hard error.

Thanks, this seems reasonable to me. The test passes in my environment so it must be perfect, right? ;) I plan to pick this up for 7.4 once 7.3-rc1 is out.

Signature · 2 lines
Cheers,
Nathan
#2 lore raw
In reply to Julian Braha
Quoted 1 line · Julian Braha

kconfig: error out for recursive range

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-unstable

Thanks!

[1/1] kconfig: error out for recursive range

      https://git.kernel.org/kbuild/c/f9f31f5f13b5e

Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.

Best regards,

Signature · 2 lines
Cheers,
Nathan