Linux Documentation
 help / color / mirror / Atom feed
* [PATCH] Documentation: warn users not to use select on choice options in Kconfig
@ 2026-07-15 22:01 Julian Braha
  2026-07-16  4:19 ` Kees Cook
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Julian Braha @ 2026-07-15 22:01 UTC (permalink / raw)
  To: nathan, nsc, corbet, skhan
  Cc: arnd, stefan.hengelein, linux-kbuild, linux-kernel, linux-doc,
	nico, officialnaumansabir, rdunlap, vegard.nossum, kees, tj,
	Julian Braha

Hengelein's master thesis about Kconfig from 2015 wrote that 'select'
does not work on member options inside of a 'choice'.

So I've re-implemented his check as part of kconfirm:
https://github.com/julianbraha/kconfirm

and discovered several instances of these dead selects in use, and
fixing them is not always trivial. For example, see:
https://lore.kernel.org/all/a3b7a752-8cc4-492a-bb62-43121b852c41@app.fastmail.com/

Let's add a warning to the documentation (a place where developers
are more likely to see it than a master's thesis...)

Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
 Documentation/kbuild/kconfig-language.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst
index d9338407c1c6..ab2822d7ca1c 100644
--- a/Documentation/kbuild/kconfig-language.rst
+++ b/Documentation/kbuild/kconfig-language.rst
@@ -164,6 +164,11 @@ applicable everywhere (see syntax).
 	That will limit the usefulness but on the other hand avoid
 	the illegal configurations all over.
 
+	select should also not be used on the member options of a choice.
+	Selecting a choice option will do nothing (dead code). Instead,
+	consider making these a dependency, or using the defaults of the
+	choice to enable the member option when it's needed.
+
 	If "select" <symbol> is followed by "if" <expr>, <symbol> will be
 	selected by the logical AND of the value of the current menu symbol
 	and <expr>. This means, the lower limit can be downgraded due to the
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-07-15 22:01 [PATCH] Documentation: warn users not to use select on choice options in Kconfig Julian Braha
@ 2026-07-16  4:19 ` Kees Cook
  2026-07-16  6:04   ` Julian Braha
  2026-07-21 10:59 ` Nicolas Schier
  2026-08-02 19:13 ` Nicolas Schier
  2 siblings, 1 reply; 10+ messages in thread
From: Kees Cook @ 2026-07-16  4:19 UTC (permalink / raw)
  To: Julian Braha
  Cc: nathan, nsc, corbet, skhan, arnd, stefan.hengelein, linux-kbuild,
	linux-kernel, linux-doc, nico, officialnaumansabir, rdunlap,
	vegard.nossum, tj

On Wed, Jul 15, 2026 at 11:01:49PM +0100, Julian Braha wrote:
> Hengelein's master thesis about Kconfig from 2015 wrote that 'select'
> does not work on member options inside of a 'choice'.
> 
> So I've re-implemented his check as part of kconfirm:
> https://github.com/julianbraha/kconfirm
> 
> and discovered several instances of these dead selects in use, and
> fixing them is not always trivial. For example, see:
> https://lore.kernel.org/all/a3b7a752-8cc4-492a-bb62-43121b852c41@app.fastmail.com/
> 
> Let's add a warning to the documentation (a place where developers
> are more likely to see it than a master's thesis...)
> 
> Signed-off-by: Julian Braha <julianbraha@gmail.com>

Yeah, it'd be good to add a checkpatch or even build-time check too.

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-07-16  4:19 ` Kees Cook
@ 2026-07-16  6:04   ` Julian Braha
  2026-07-29 15:10     ` Jani Nikula
  0 siblings, 1 reply; 10+ messages in thread
From: Julian Braha @ 2026-07-16  6:04 UTC (permalink / raw)
  To: Kees Cook
  Cc: nathan, nsc, corbet, skhan, arnd, stefan.hengelein, linux-kbuild,
	linux-kernel, linux-doc, nico, officialnaumansabir, rdunlap,
	vegard.nossum, tj

Hi Kees,

On 7/16/26 05:19, Kees Cook wrote:
> Yeah, it'd be good to add a checkpatch or even build-time check too.

I'll look into adding a check for this into the kconfig interpreter.

- Julian Braha

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-07-15 22:01 [PATCH] Documentation: warn users not to use select on choice options in Kconfig Julian Braha
  2026-07-16  4:19 ` Kees Cook
@ 2026-07-21 10:59 ` Nicolas Schier
  2026-08-02 19:13 ` Nicolas Schier
  2 siblings, 0 replies; 10+ messages in thread
From: Nicolas Schier @ 2026-07-21 10:59 UTC (permalink / raw)
  To: nathan, corbet, skhan, Julian Braha
  Cc: arnd, stefan.hengelein, linux-kbuild, linux-kernel, linux-doc,
	nico, officialnaumansabir, rdunlap, vegard.nossum, kees, tj

On Wed, 15 Jul 2026 23:01:49 +0100, Julian Braha wrote:
> Documentation: warn users not to use select on choice options in Kconfig

Applied to kbuild/linux.git (kbuild-next-unstable), thanks!

[1/1] Documentation: warn users not to use select on choice options in Kconfig
      https://git.kernel.org/kbuild/c/d10cfe72

Please look out for regression or issue reports or other follow up
comments, as they may result in the patch/series getting dropped,
reverted or modified (e.g. trailers).

Patches applied to the kbuild-next-unstable branch are accepted pending
wider testing in linux-next and any post-commit review; they will
generally be moved to the kbuild-next branch in about a week if no
issues are found.

Best regards,
-- 
Nicolas



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-07-16  6:04   ` Julian Braha
@ 2026-07-29 15:10     ` Jani Nikula
  0 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2026-07-29 15:10 UTC (permalink / raw)
  To: Julian Braha, Kees Cook
  Cc: nathan, nsc, corbet, skhan, arnd, stefan.hengelein, linux-kbuild,
	linux-kernel, linux-doc, nico, officialnaumansabir, rdunlap,
	vegard.nossum, tj

On Thu, 16 Jul 2026, Julian Braha <julianbraha@gmail.com> wrote:
> Hi Kees,
>
> On 7/16/26 05:19, Kees Cook wrote:
>> Yeah, it'd be good to add a checkpatch or even build-time check too.
>
> I'll look into adding a check for this into the kconfig interpreter.

This. I wish there was a kconfig lint option that would whine about all
the things that kconfig-language.rst explicitly tells you *not* to use
select for. (So I could perhaps eventually stop replying to people with
that stuff.)

BR,
Jani.


-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-07-15 22:01 [PATCH] Documentation: warn users not to use select on choice options in Kconfig Julian Braha
  2026-07-16  4:19 ` Kees Cook
  2026-07-21 10:59 ` Nicolas Schier
@ 2026-08-02 19:13 ` Nicolas Schier
  2026-08-02 19:36   ` Julian Braha
  2 siblings, 1 reply; 10+ messages in thread
From: Nicolas Schier @ 2026-08-02 19:13 UTC (permalink / raw)
  To: Julian Braha
  Cc: nathan, corbet, skhan, arnd, stefan.hengelein, linux-kbuild,
	linux-kernel, linux-doc, nico, officialnaumansabir, rdunlap,
	vegard.nossum, kees, tj

On Wed, Jul 15, 2026 at 11:01:49PM +0100, Julian Braha wrote:
> Hengelein's master thesis about Kconfig from 2015 wrote that 'select'
> does not work on member options inside of a 'choice'.

is this true also for 'imply'?  Adding the check to kconfig seems to be
pretty simple:

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index b2d8d4e11e07..149d3ee59b58 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -287,6 +287,11 @@ static void sym_check_prop(struct symbol *sym)
 				    "'%s' has wrong type. '%s' only "
 				    "accept arguments of bool and "
 				    "tristate type", sym2->name, use);
+			if (sym_is_choice_value(sym2))
+				prop_warn(prop,
+				    "config symbol '%s' uses %s for '%s', "
+				    "but '%s' is a choice value", sym->name,
+				    use, sym2->name, sym2->name);
 			break;
 		case P_RANGE:
 			if (sym->type != S_INT && sym->type != S_HEX)

which currently reveals

kernel/time/Kconfig:136:warning: config symbol 'NO_HZ_FULL' uses select for 'VIRT_CPU_ACCOUNTING_GEN', but 'VIRT_CPU_ACCOUNTING_GEN' is a choice value
drivers/mtd/maps/Kconfig:104:warning: config symbol 'MTD_PHYSMAP_IXP4XX' uses select for 'MTD_CFI_BE_BYTE_SWAP', but 'MTD_CFI_BE_BYTE_SWAP' is a choice value
drivers/tee/qcomtee/Kconfig:8:warning: config symbol 'QCOMTEE' uses select for 'QCOM_TZMEM_MODE_SHMBRIDGE', but 'QCOM_TZMEM_MODE_SHMBRIDGE' is a choice value

on linux-next, with the NO_HZ_FULL also being addressed by Julian [1].

Julian, please call out if you want help for pushing these.

I am considering to prepare a patch and add it for kbuild-for-next (but
not to kbuild-next) to raise attention.


Kind regards,
Nicolas

[1]: https://lore.kernel.org/r/20260801160140.2391000-1-julianbraha@gmail.com

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-08-02 19:13 ` Nicolas Schier
@ 2026-08-02 19:36   ` Julian Braha
  2026-08-03 17:47     ` Nathan Chancellor
  0 siblings, 1 reply; 10+ messages in thread
From: Julian Braha @ 2026-08-02 19:36 UTC (permalink / raw)
  To: nathan, corbet, skhan, arnd, stefan.hengelein, linux-kbuild,
	linux-kernel, linux-doc, nico, officialnaumansabir, rdunlap,
	vegard.nossum, kees, tj

Hi Nicolas,

On 8/2/26 20:13, Nicolas Schier wrote:
> On Wed, Jul 15, 2026 at 11:01:49PM +0100, Julian Braha wrote:
>> Hengelein's master thesis about Kconfig from 2015 wrote that 'select'
>> does not work on member options inside of a 'choice'.
> 
> is this true also for 'imply'?  

Yes, the same problem goes for imply. But I didn't find any of these
'imply-choice' instances in use. Of course, if we're going to warn /
error for select, then it makes sense to do the same for imply.

> Adding the check to kconfig seems to be
> pretty simple:
> 
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index b2d8d4e11e07..149d3ee59b58 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -287,6 +287,11 @@ static void sym_check_prop(struct symbol *sym)
>  				    "'%s' has wrong type. '%s' only "
>  				    "accept arguments of bool and "
>  				    "tristate type", sym2->name, use);
> +			if (sym_is_choice_value(sym2))
> +				prop_warn(prop,
> +				    "config symbol '%s' uses %s for '%s', "
> +				    "but '%s' is a choice value", sym->name,
> +				    use, sym2->name, sym2->name);
>  			break;
>  		case P_RANGE:
>  			if (sym->type != S_INT && sym->type != S_HEX)
> 
> which currently reveals
> 
> kernel/time/Kconfig:136:warning: config symbol 'NO_HZ_FULL' uses select for 'VIRT_CPU_ACCOUNTING_GEN', but 'VIRT_CPU_ACCOUNTING_GEN' is a choice value
> drivers/mtd/maps/Kconfig:104:warning: config symbol 'MTD_PHYSMAP_IXP4XX' uses select for 'MTD_CFI_BE_BYTE_SWAP', but 'MTD_CFI_BE_BYTE_SWAP' is a choice value
> drivers/tee/qcomtee/Kconfig:8:warning: config symbol 'QCOMTEE' uses select for 'QCOM_TZMEM_MODE_SHMBRIDGE', but 'QCOM_TZMEM_MODE_SHMBRIDGE' is a choice value
> 
> on linux-next, with the NO_HZ_FULL also being addressed by Julian [1].
> 
> Julian, please call out if you want help for pushing these.

Thanks for offering :)

I actually detected 5 of these across all architectures, and already
submitted patches for all of them (thank you, Arnd, for all of your
help):
1.
https://lore.kernel.org/all/20260729203845.387239-1-julianbraha@gmail.com/
2.
https://lore.kernel.org/all/20260801160140.2391000-1-julianbraha@gmail.com/
3.
https://lore.kernel.org/all/20260714112047.2304856-1-julianbraha@gmail.com/
4.
https://lore.kernel.org/all/20260723104933.117413-1-julianbraha@gmail.com/

With #5 already in linux-next:
5.
https://lore.kernel.org/all/20260723122818.437802-1-julianbraha@gmail.com/

> I am considering to prepare a patch and add it for kbuild-for-next (but
> not to kbuild-next) to raise attention.

I think the Kconfig interpreter should completely error out for these,
but of course, we need to wait all of these patches to be applied first.

- Julian Braha

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-08-02 19:36   ` Julian Braha
@ 2026-08-03 17:47     ` Nathan Chancellor
  2026-08-03 18:26       ` Julian Braha
  0 siblings, 1 reply; 10+ messages in thread
From: Nathan Chancellor @ 2026-08-03 17:47 UTC (permalink / raw)
  To: Julian Braha
  Cc: corbet, skhan, arnd, stefan.hengelein, linux-kbuild, linux-kernel,
	linux-doc, nico, officialnaumansabir, rdunlap, vegard.nossum,
	kees, tj

On Sun, Aug 02, 2026 at 08:36:58PM +0100, Julian Braha wrote:
> On 8/2/26 20:13, Nicolas Schier wrote:
> > Adding the check to kconfig seems to be
> > pretty simple:
> > 
> > diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> > index b2d8d4e11e07..149d3ee59b58 100644
> > --- a/scripts/kconfig/menu.c
> > +++ b/scripts/kconfig/menu.c
> > @@ -287,6 +287,11 @@ static void sym_check_prop(struct symbol *sym)
> >  				    "'%s' has wrong type. '%s' only "
> >  				    "accept arguments of bool and "
> >  				    "tristate type", sym2->name, use);
> > +			if (sym_is_choice_value(sym2))
> > +				prop_warn(prop,
> > +				    "config symbol '%s' uses %s for '%s', "
> > +				    "but '%s' is a choice value", sym->name,
> > +				    use, sym2->name, sym2->name);
> >  			break;
> >  		case P_RANGE:
> >  			if (sym->type != S_INT && sym->type != S_HEX)
...
> I actually detected 5 of these across all architectures, and already
> submitted patches for all of them (thank you, Arnd, for all of your
> help):
> 1.
> https://lore.kernel.org/all/20260729203845.387239-1-julianbraha@gmail.com/
> 2.
> https://lore.kernel.org/all/20260801160140.2391000-1-julianbraha@gmail.com/
> 3.
> https://lore.kernel.org/all/20260714112047.2304856-1-julianbraha@gmail.com/
> 4.
> https://lore.kernel.org/all/20260723104933.117413-1-julianbraha@gmail.com/
> 
> With #5 already in linux-next:
> 5.
> https://lore.kernel.org/all/20260723122818.437802-1-julianbraha@gmail.com/
> 
> > I am considering to prepare a patch and add it for kbuild-for-next (but
> > not to kbuild-next) to raise attention.
> 
> I think the Kconfig interpreter should completely error out for these,
> but of course, we need to wait all of these patches to be applied first.

It looks like number 4 has been picked up as well. Given that we only
need three more patches to be accepted to turn this into a hard error, I
think it would be better to hold off on taking the documentation patch
and just push for the hard error next cycle. If these patches are not
applied to other trees before 7.3-rc1, we can ask to take them via
Kbuild with Acks and/or stable branches for 7.4.

-- 
Cheers,
Nathan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-08-03 17:47     ` Nathan Chancellor
@ 2026-08-03 18:26       ` Julian Braha
  2026-08-04 11:47         ` Nicolas Schier
  0 siblings, 1 reply; 10+ messages in thread
From: Julian Braha @ 2026-08-03 18:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: corbet, skhan, arnd, stefan.hengelein, linux-kbuild, linux-kernel,
	linux-doc, nico, officialnaumansabir, rdunlap, vegard.nossum,
	kees, tj

On 8/3/26 18:47, Nathan Chancellor wrote:
> It looks like number 4 has been picked up as well. Given that we only
> need three more patches to be accepted to turn this into a hard error, I
> think it would be better to hold off on taking the documentation patch
> and just push for the hard error next cycle. If these patches are not
> applied to other trees before 7.3-rc1, we can ask to take them via
> Kbuild with Acks and/or stable branches for 7.4.

All good on my end, we can drop this patch.

- Julian Braha

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Documentation: warn users not to use select on choice options in Kconfig
  2026-08-03 18:26       ` Julian Braha
@ 2026-08-04 11:47         ` Nicolas Schier
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Schier @ 2026-08-04 11:47 UTC (permalink / raw)
  To: Julian Braha
  Cc: Nathan Chancellor, corbet, skhan, arnd, stefan.hengelein,
	linux-kbuild, linux-kernel, linux-doc, nico, officialnaumansabir,
	rdunlap, vegard.nossum, kees, tj

On Mon, Aug 03, 2026 at 07:26:28PM +0100, Julian Braha wrote:
> On 8/3/26 18:47, Nathan Chancellor wrote:
> > It looks like number 4 has been picked up as well. Given that we only
> > need three more patches to be accepted to turn this into a hard error, I
> > think it would be better to hold off on taking the documentation patch
> > and just push for the hard error next cycle. If these patches are not
> > applied to other trees before 7.3-rc1, we can ask to take them via
> > Kbuild with Acks and/or stable branches for 7.4.

sounds good.  I'll prepare a patch for the hard error.

> All good on my end, we can drop this patch.

thanks, removed commit 63dad1769941 ("Documentation: warn users not to
use select on choice options in Kconfig") from kbuild-next-unstable.

> 
> - Julian Braha

-- 
Nicolas

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-08-04 11:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 22:01 [PATCH] Documentation: warn users not to use select on choice options in Kconfig Julian Braha
2026-07-16  4:19 ` Kees Cook
2026-07-16  6:04   ` Julian Braha
2026-07-29 15:10     ` Jani Nikula
2026-07-21 10:59 ` Nicolas Schier
2026-08-02 19:13 ` Nicolas Schier
2026-08-02 19:36   ` Julian Braha
2026-08-03 17:47     ` Nathan Chancellor
2026-08-03 18:26       ` Julian Braha
2026-08-04 11:47         ` Nicolas Schier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox