archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] Documentation: kbuild: explain handling optional dependencies
@ 2023-09-17 19:19 Arnd Bergmann
  2023-09-25  7:06 ` Masahiro Yamada
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2023-09-17 19:19 UTC (permalink / raw)
  To: Masahiro Yamada, Jonathan Corbet
  Cc: Arnd Bergmann, Javier Martinez Canillas, Sakari Ailus,
	Nicolas Schier, Nathan Chancellor, Nick Desaulniers,
	linux-kbuild, linux-doc, linux-kernel

From: Arnd Bergmann <>

This problem frequently comes up in randconfig testing, with
drivers failing to link because of a dependency on an optional

The Kconfig language for this is very confusing, so try to
document it in "Kconfig hints" section.

Reviewed-by: Javier Martinez Canillas <>
Reviewed-by: Sakari Ailus <>
Reviewed-by: Nicolas Schier <>
Signed-off-by: Arnd Bergmann <>
v2: fix typos pointed out by Nicolas Schier
 Documentation/kbuild/kconfig-language.rst | 26 +++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst
index 858ed5d80defe..0135905c0aa35 100644
--- a/Documentation/kbuild/kconfig-language.rst
+++ b/Documentation/kbuild/kconfig-language.rst
@@ -573,6 +573,32 @@ above, leading to:
 	bool "Support for foo hardware"
+Optional dependencies
+Some drivers are able to optionally use a feature from another module
+or build cleanly with that module disabled, but cause a link failure
+when trying to use that loadable module from a built-in driver.
+The most common way to express this optional dependency in Kconfig logic
+uses the slightly counterintuitive::
+  config FOO
+	tristate "Support for foo hardware"
+	depends on BAR || !BAR
+This means that there is either a dependency on BAR that disallows
+the combination of FOO=y with BAR=m, or BAR is completely disabled.
+For a more formalized approach if there are multiple drivers that have
+the same dependency, a helper symbol can be used, like::
+  config FOO
+	tristate "Support for foo hardware"
+	depends on BAR_OPTIONAL
+  config BAR_OPTIONAL
+	def_tristate BAR || !BAR
 Kconfig recursive dependency limitations

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

end of thread, other threads:[~2024-02-15 13:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-17 19:19 [PATCH] [v2] Documentation: kbuild: explain handling optional dependencies Arnd Bergmann
2023-09-25  7:06 ` Masahiro Yamada
2024-02-15 12:38   ` Nicolas Schier
2024-02-15 13:40     ` Masahiro Yamada
2024-02-15 13:51       ` Nicolas Schier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).