Re: [PATCH 2/2] kconfig: error on reverse range
From: Nicolas Schier
Date: Thu Sep 24 2026 - 07:16:32 EST
> As discussed on kconfirm v4 [1], it was decided to move checks directly
> into the kconfig interpreter once where are no findings from kconfirm.
s/where/there/
> This "reverse range" currently has no findings across the tree, so let's
> add the check.
>
> Currently, if a reverse range is attempted, such as:
>
> config EXAMPLE
> int "Reverse range example"
> range 2 1
>
> then the value of the option defaults to its "lower" limit of 2. If the
> option is visible in the frontend, then the user gets trapped in the value
> selection interface, since there is no value that is actually valid for
> the user to set.
>
> Note that this only checks ranges that use constant values. Statically
> checking ranges using symbols would require SAT solving, or similar.
>
> Link: https://lore.kernel.org/all/20260904220559.GB2787252@ax162/ [1]
> Assisted-by: LLM
> Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
>
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index 118af2dde722..cc335f6db257 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -274,9 +274,9 @@ static int menu_validate_number(struct symbol *sym, struct symbol *sym2,
> static int sym_check_prop(struct symbol *sym)
> {
> struct property *prop;
> - struct symbol *sym2;
> + struct symbol *sym2, *lower, *upper;
> char *use;
> - int errors = 0;
> + int errors = 0, numeric_errors = 0;
>
> for (prop = sym->prop; prop; prop = prop->next) {
> switch (prop->type) {
> @@ -325,8 +325,22 @@ static int sym_check_prop(struct symbol *sym)
> if (sym->type != S_INT && sym->type != S_HEX)
> prop_warn(prop, "range is only allowed "
> "for int or hex symbols");
> - errors += menu_validate_number(sym, prop->expr->left.sym, prop);
> - errors += menu_validate_number(sym, prop->expr->right.sym, prop);
> + lower = prop->expr->left.sym;
> + upper = prop->expr->right.sym;
> + numeric_errors += menu_validate_number(sym, lower, prop);
> + numeric_errors += menu_validate_number(sym, upper, prop);
> + errors += numeric_errors;
> + if (numeric_errors || lower->type != S_UNKNOWN || upper->type != S_UNKNOWN)
> + break;
> +
> + if ((sym->type == S_INT &&
> + strtoll(lower->name, NULL, 10) > strtoll(upper->name, NULL, 10)) ||
> + (sym->type == S_HEX &&
> + strtoull(lower->name, NULL, 16) > strtoull(upper->name, NULL, 16))) {
> + prop_err(prop, "range lower limit '%s' is greater than upper limit '%s'",
> + lower->name, upper->name);
> + errors++;
> + }
Thanks, looks good to me. I don't like that we do these strto{u,}ll()
conversions everywhere repeated. But I think it's ok for now.
Tested-by: Nicolas Schier <n.schier@xxxxxxxxx>
Reviewed-by: Nicolas Schier <n.schier@xxxxxxxxx>
--
Nicolas