Re: [PATCH] kconfig: fix extra output from savedefconfig on out-of-range defaults

From: Nathan Chancellor

Date: Thu Sep 03 2026 - 18:29:05 EST


> The Kconfig interpreter currently allows defaults that are outside of the
> range bounds.
>
> In these cases, the 'sym_validate_range' function will adjust the default
> value to the nearest range bound. For example, see this example:
>
> config A
> int
> range 1 2
> default 16
>
> Here, since the default value of 16 is greater than the bounds, the
> effective default value gets adjusted down to the upper bound, 2.
>
> However, 'savedefconfig' writes non-default values, and without being
> aware of the automatic adjustment to the range bound, it would write: A=2

Should that 'A=2' be 'A=16'?

> This limitation is also documented in a comment: "The following fails to
> handle the situation where a default value is further limited by the valid
> range."
>
> To resolve this, let's factor out the default-range adjustment logic from
> the existing 'sym_validate_range' function into its own
> 'sym_get_near_range_bound' function for 'savedefconfig' to use too, so
> that it compares against the effective value.
>
> Adds tests, accordingly.
>
> Fixes: 7cf3d73b4360 ("kconfig: add savedefconfig")
> Assisted-by: Codex:gpt-5.6-sol
> Reported-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> Closes: https://lore.kernel.org/lkml/CAMuHMdVyUAA3L4mUkSjmnuE3cvj-+N8z-Bhxsh1wa-FQWc=fjw@xxxxxxxxxxxxxx/
> Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>

Thanks for the patch!

Reviewed-by: Nathan Chancellor <nathan@xxxxxxxxxx>

Given this is a long standing issue, it should probably go via
kbuild-next for 7.4, especially in case this results in problems like
noted downthread. I would revert commit ab74edaeb1ae ("erofs: Fix
EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS default logic") on top of that.

I will wait a little bit for the folks CC'd downthread to reply to those
instances impacted by this change before applying this.

--
Cheers,
Nathan