Re: [PATCH v2 3/5] kconfig: check for hex and int mismatches

From: Nicolas Schier

Date: Thu Sep 17 2026 - 12:22:02 EST


On Tue, Sep 15, 2026 at 10:15:06PM +0100, Julian Braha wrote:
> Using a numeric option of one type (e.g. 'int') to determine the value of
> a different numeric type (e.g. 'hex') currently fails silently in various
> ways if attempted, because the underlying string representation is naively
> reused.
>
> Example 1:
>
> config I
> int
> default -1
>
> config HEX_DEFAULT_INT
> hex
> default I
>
> Here, HEX_DEFAULT_INT actually gets set to '0x-1', which is of course not
> a valid hex value.
>
> Example 2:
>
> config H
> hex
> default A
>
> config INT_DEFAULT_HEX
> int
> default H
>
> Here, INT_DEFAULT_HEX actually gets set to 'A', without even converting
> into the base-10 equivalent of 10. This value, 'A', is otherwise a
> rejected int value if entered in the frontend, or read in from an existing
> .config file.
>
> These int-hex mismatches currently do not appear anywhere in the tree, so
> it is already safe to make these error out.
>
> Assisted-by: LLM
> Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
> ---
> scripts/kconfig/menu.c | 2 +-
> .../kconfig/tests/err_num_mismatch/Kconfig | 38 +++++++++++++++++++
> .../tests/err_num_mismatch/__init__.py | 9 +++++
> .../tests/err_num_mismatch/expected_stderr | 4 ++
> 4 files changed, 52 insertions(+), 1 deletion(-)
> create mode 100644 scripts/kconfig/tests/err_num_mismatch/Kconfig
> create mode 100644 scripts/kconfig/tests/err_num_mismatch/__init__.py
> create mode 100644 scripts/kconfig/tests/err_num_mismatch/expected_stderr
>

Thanks, error-out is really a good thing for now. Actually, I am one of
those who'd expect that Kconfig auto-converts hex ←→ int; so, thanks for
enforcing clarity.

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

--
Nicolas