From: Julian Braha <julianbraha@gmail.com>
To: nathan@kernel.org, nsc@kernel.org, corbet@lwn.net,
skhan@linuxfoundation.org
Cc: jani.nikula@linux.intel.com, arnd@arndb.de,
stefan.hengelein@fau.de, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
nico@fluxnic.net, officialnaumansabir@gmail.com,
rdunlap@infradead.org, vegard.nossum@oracle.com, kees@kernel.org,
tj@kernel.org, Julian Braha <julianbraha@gmail.com>
Subject: [PATCH] Documentation: warn against using int, hex, string options as expressions in Kconfig
Date: Thu, 30 Jul 2026 15:01:08 +0100 [thread overview]
Message-ID: <20260730140108.683967-1-julianbraha@gmail.com> (raw)
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.
See also this related patch:
https://lore.kernel.org/all/20260729210546.394392-1-julianbraha@gmail.com/
Let's warn users against this usage.
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
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
--
2.55.0
next reply other threads:[~2026-07-30 14:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 14:01 Julian Braha [this message]
2026-07-31 0:25 ` [PATCH] Documentation: warn against using int, hex, string options as expressions in Kconfig Nathan Chancellor
2026-07-31 9:43 ` Julian Braha
2026-07-31 10:33 ` Arnd Bergmann
2026-07-31 0:32 ` Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260730140108.683967-1-julianbraha@gmail.com \
--to=julianbraha@gmail.com \
--cc=arnd@arndb.de \
--cc=corbet@lwn.net \
--cc=jani.nikula@linux.intel.com \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nico@fluxnic.net \
--cc=nsc@kernel.org \
--cc=officialnaumansabir@gmail.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=stefan.hengelein@fau.de \
--cc=tj@kernel.org \
--cc=vegard.nossum@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox