Re: [PATCH] kconfig: fix extra output from savedefconfig on out-of-range defaults
From: Julian Braha
Date: Thu Sep 03 2026 - 19:20:36 EST
On 9/3/26 23:28, Nathan Chancellor wrote:
>> 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'?
No typo, this example is adapted from the original report where it
needlessly writes the adjusted default. In the original it was 1, here
it's 2. [1]
>
>> 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.
>
Makes sense to me, and thanks for reviewing!
[1]
https://lore.kernel.org/lkml/c480ed6b8bf38822263e2c5b7cf32b28600f212d.1787219898.git.geert+renesas@xxxxxxxxx/
- Julian Braha