Re: [PATCH] Documentation: warn against using int, hex, string options as expressions in Kconfig
Randy Dunlap <[email protected]> Thu, 30 Jul 2026 17:32:53 -0700
| Newsgroups | gmane.linux.kernel,gmane.linux.kbuild.devel,gmane.linux.documentation |
|---|---|
| Message-ID | <[email protected]> |
Hi, I haven't had time to really look at this yet, but... On 7/30/26 7:01 AM, Julian Braha wrote: > I've been working on type checking Kconfig, and found some instances of > dead code due to conditions that always evaluate to false. > > For example: > > config FOO > int > > config BAR > bool > default 'y' if FOO > > This 'if FOO' will always be false, regardless of FOO's value (even when > FOO=1). The same goes for strings and hex. Does it help to say default y if FOO > 0 or default y if FOO != 0 Oh, I think that's what you suggested below. :) Sorry, I just read that part. This is unfortunate IMO but yes, let's at least document it. Thanks. > See also this related patch: > https://lore.kernel.org/all/[email protected]/ > > Let's warn users against this usage. > > Signed-off-by: Julian Braha <[email protected]> > --- > Documentation/kbuild/kconfig-language.rst | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst > index ab2822d7ca1c..aee84b294a56 100644 > --- a/Documentation/kbuild/kconfig-language.rst > +++ b/Documentation/kbuild/kconfig-language.rst > @@ -320,6 +320,17 @@ An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2 > respectively for calculations). A menu entry becomes visible when its > expression evaluates to 'm' or 'y'. > > +Note that options of int, hex, or string type should not be used directly > +as expressions; these will always evaluate to 'n'. Instead, to check if > +one of these options is in use, consider using one of these heuristics:: > + > + <symbol> != 0 > + <symbol> != 0x0 > + <symbol> != "" > + > +because int, hex, and string options will take these values of '0', '0x0', > +and the empty string, respectively, when the dependencies are unmet. > + > There are two types of symbols: constant and non-constant symbols. > Non-constant symbols are the most common ones and are defined with the > 'config' statement. Non-constant symbols consist entirely of alphanumeric -- ~Randy