Re: [PATCH v2 1/5] kconfig: promote invalid numeric reference from warning to error

From: Nicolas Schier

Date: Thu Sep 17 2026 - 06:54:53 EST


On Tue, Sep 15, 2026 at 10:15:04PM +0100, Julian Braha wrote:
> The Kconfig interpreter already warns if a numeric option attempts to use
> a non-numeric option (bool, tristate, or string) to set its value (for
> example, with a 'default' or 'range').
>
> Since there is nowhere in the tree that attempts this, we can safely
> promote this check from warning to error.
>
> Assisted-by: LLM
> Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
> ---
> scripts/kconfig/lkc.h | 2 +-
> scripts/kconfig/menu.c | 39 ++++++----
> scripts/kconfig/parser.y | 2 +-
> .../tests/err_num_non_numeric_ref/Kconfig | 75 +++++++++++++++++++
> .../tests/err_num_non_numeric_ref/__init__.py | 9 +++
> .../err_num_non_numeric_ref/expected_stderr | 14 ++++
> 6 files changed, 126 insertions(+), 15 deletions(-)
> create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/Kconfig
> create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/__init__.py
> create mode 100644 scripts/kconfig/tests/err_num_non_numeric_ref/expected_stderr
>
> diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
> index 7e6f6ca299cf..bbc99f75b416 100644
> --- a/scripts/kconfig/lkc.h
> +++ b/scripts/kconfig/lkc.h
> @@ -89,7 +89,7 @@ struct property *menu_add_prompt(enum prop_type type, const char *prompt,
> struct expr *dep);
> void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
> void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
> -void menu_finalize(void);
> +int menu_finalize(void);
> void menu_set_type(int type);
>
> extern struct menu rootmenu;
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index 9c079e92a9ed..99a57ce0fdc9 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -240,11 +240,12 @@ static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
> (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
> }
>
> -static void sym_check_prop(struct symbol *sym)
> +static int sym_check_prop(struct symbol *sym)
> {
> struct property *prop;
> struct symbol *sym2;
> char *use;
> + int errors = 0;
>
> for (prop = sym->prop; prop; prop = prop->next) {
> switch (prop->type) {
> @@ -258,10 +259,13 @@ static void sym_check_prop(struct symbol *sym)
> break;
> sym2 = prop_get_symbol(prop);
> if (sym->type == S_HEX || sym->type == S_INT) {
> - if (!menu_validate_number(sym, sym2))
> - prop_warn(prop,
> - "'%s': number is invalid",
> - sym->name);
> + if (!menu_validate_number(sym, sym2)) {
> + fprintf(stderr,
> + "%s:%d: error: '%s': number is invalid\n",
> + prop->filename, prop->lineno,
> + sym->name);

I think it would be reasonable to add a prop_err() function for that.
But that's a possible follow-up.

Reviewed-by: Nicolas Schier <n.schier@xxxxxxxxx>

--
Nicolas