Re: [PATCH 1/3] kconfig: Add "def_string", "def_int" and "def_hex"
From: Kees Cook
Date: Sat Sep 19 2026 - 23:40:34 EST
On Sat, Sep 19, 2026 at 04:34:54PM +0100, Julian Braha wrote:
> On 9/19/26 01:59, Kees Cook wrote:
> [...]
> the X condition here only applies to the value of y, but not to the type
> declaration of bool. Besides hurting readability, I can imagine a user
> making a mistake by attempting something like this:
>
> def_bool 'y' if X
> def_tristate 'y' if !X
>
> thinking that they're making the type conditional. Of course, the
> interpreter warns if this is attempted, so you won't actually find any
> of these in the tree.
Yeah, _this_ case is warned on, so no real issue there.
> The second problem, is that since the order of defaults matters and
> conditions can shadow each other, def_<type> makes it harder for users
> to get defaults right. In the past, I've seen several config options
> with bugged defaults due to 'default' + 'def_<type>' [2][3][4].
This is the one I, too, got worried about. From your example:
config GUEST_STATE_BUFFER_TEST
- def_tristate n
+ def_tristate KUNIT_ALL_TESTS
prompt "Enable Guest State Buffer unit tests"
depends on KUNIT
depends on KVM_BOOK3S_HV_POSSIBLE
- default KUNIT_ALL_TESTS
help
Is there a way to detect this state? (I assume as a follow-up; it's a
general problem.)
> > Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
>
> Tested-by: Julian Braha <julianbraha@xxxxxxxxx>
> Reviewed-by: Julian Braha <julianbraha@xxxxxxxxx>
Thanks!
--
Kees Cook