Skip to content

Commit dafbec3

Browse files
krzkmasahir0y
authored andcommitted
docs: kconfig: Mention IS_REACHABLE as way for optional dependency
Several drivers express optional Kconfig dependency with FOO || !FOO, but for many choices this is not suitable: lack of stubs for !FOO like in HWMON. Describe the second, less favorable way of optional dependency with IS_REACHABLE by moving the code from "imply" chapter to "Optional dependencies". Cc: Masahiro Yamada <[email protected]> Cc: Arnd Bergmann <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Acked-by: Arnd Bergmann <[email protected]>
1 parent 4f81aee commit dafbec3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Documentation/kbuild/kconfig-language.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,6 @@ applicable everywhere (see syntax).
194194
ability to hook into a secondary subsystem while allowing the user to
195195
configure that subsystem out without also having to unset these drivers.
196196

197-
Note: If the combination of FOO=y and BAZ=m causes a link error,
198-
you can guard the function call with IS_REACHABLE()::
199-
200-
foo_init()
201-
{
202-
if (IS_REACHABLE(CONFIG_BAZ))
203-
baz_register(&foo);
204-
...
205-
}
206-
207197
Note: If the feature provided by BAZ is highly desirable for FOO,
208198
FOO should imply not only BAZ, but also its dependency BAR::
209199

@@ -588,7 +578,9 @@ uses the slightly counterintuitive::
588578
depends on BAR || !BAR
589579

590580
This means that there is either a dependency on BAR that disallows
591-
the combination of FOO=y with BAR=m, or BAR is completely disabled.
581+
the combination of FOO=y with BAR=m, or BAR is completely disabled. The BAR
582+
module must provide all the stubs for !BAR case.
583+
592584
For a more formalized approach if there are multiple drivers that have
593585
the same dependency, a helper symbol can be used, like::
594586

@@ -599,6 +591,21 @@ the same dependency, a helper symbol can be used, like::
599591
config BAR_OPTIONAL
600592
def_tristate BAR || !BAR
601593

594+
Much less favorable way to express optional dependency is IS_REACHABLE() within
595+
the module code, useful for example when the module BAR does not provide
596+
!BAR stubs::
597+
598+
foo_init()
599+
{
600+
if (IS_REACHABLE(CONFIG_BAR))
601+
bar_register(&foo);
602+
...
603+
}
604+
605+
IS_REACHABLE() is generally discouraged, because the code will be silently
606+
discarded, when CONFIG_BAR=m and this code is built-in. This is not what users
607+
usually expect when enabling BAR as module.
608+
602609
Kconfig recursive dependency limitations
603610
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
604611

0 commit comments

Comments
 (0)