2021-06-01 21:35:29

by Bjorn Helgaas

[permalink] [raw]
Subject: [PATCH] kconfig.h: explain IS_MODULE(), IS_ENABLED()

From: Bjorn Helgaas <[email protected]>

Extend IS_MODULE() and IS_ENABLED comments to explain why one might use
"#if IS_ENABLED(CONFIG_FOO)" instead of "#ifdef CONFIG_FOO".

To wit, "#ifdef CONFIG_FOO" is true only for CONFIG_FOO=y, while
"#if IS_ENABLED(CONFIG_FOO)" is true for both CONFIG_FOO=y and
CONFIG_FOO=m.

This is because "CONFIG_FOO=m" in .config does not result in "CONFIG_FOO"
being defined. The actual definitions are in autoconf.h, where:

CONFIG_FOO=y results in #define CONFIG_FOO 1
CONFIG_FOO=m results in #define CONFIG_FOO_MODULE 1

Signed-off-by: Bjorn Helgaas <[email protected]>
---
include/linux/kconfig.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index cc8fa109cfa3..20d1079e92b4 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -51,7 +51,8 @@

/*
* IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
- * otherwise.
+ * otherwise. CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
+ * autoconf.h.
*/
#define IS_MODULE(option) __is_defined(option##_MODULE)

@@ -66,7 +67,8 @@

/*
* IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
- * 0 otherwise.
+ * 0 otherwise. Note that CONFIG_FOO=y results in "#define CONFIG_FOO 1" in
+ * autoconf.h, while CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1".
*/
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))

--
2.25.1


2021-06-01 22:19:38

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] kconfig.h: explain IS_MODULE(), IS_ENABLED()

On 6/1/21 2:31 PM, Bjorn Helgaas wrote:
> From: Bjorn Helgaas <[email protected]>
>
> Extend IS_MODULE() and IS_ENABLED comments to explain why one might use
> "#if IS_ENABLED(CONFIG_FOO)" instead of "#ifdef CONFIG_FOO".
>
> To wit, "#ifdef CONFIG_FOO" is true only for CONFIG_FOO=y, while
> "#if IS_ENABLED(CONFIG_FOO)" is true for both CONFIG_FOO=y and
> CONFIG_FOO=m.
>
> This is because "CONFIG_FOO=m" in .config does not result in "CONFIG_FOO"
> being defined. The actual definitions are in autoconf.h, where:
>
> CONFIG_FOO=y results in #define CONFIG_FOO 1
> CONFIG_FOO=m results in #define CONFIG_FOO_MODULE 1
>
> Signed-off-by: Bjorn Helgaas <[email protected]>

Acked-by: Randy Dunlap <[email protected]>


Thanks.

> ---
> include/linux/kconfig.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
> index cc8fa109cfa3..20d1079e92b4 100644
> --- a/include/linux/kconfig.h
> +++ b/include/linux/kconfig.h
> @@ -51,7 +51,8 @@
>
> /*
> * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
> - * otherwise.
> + * otherwise. CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
> + * autoconf.h.
> */
> #define IS_MODULE(option) __is_defined(option##_MODULE)
>
> @@ -66,7 +67,8 @@
>
> /*
> * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
> - * 0 otherwise.
> + * 0 otherwise. Note that CONFIG_FOO=y results in "#define CONFIG_FOO 1" in
> + * autoconf.h, while CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1".
> */
> #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
>
>


--
~Randy

2021-06-05 14:51:15

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kconfig.h: explain IS_MODULE(), IS_ENABLED()

On Wed, Jun 2, 2021 at 6:53 AM Randy Dunlap <[email protected]> wrote:
>
> On 6/1/21 2:31 PM, Bjorn Helgaas wrote:
> > From: Bjorn Helgaas <[email protected]>
> >
> > Extend IS_MODULE() and IS_ENABLED comments to explain why one might use
> > "#if IS_ENABLED(CONFIG_FOO)" instead of "#ifdef CONFIG_FOO".
> >
> > To wit, "#ifdef CONFIG_FOO" is true only for CONFIG_FOO=y, while
> > "#if IS_ENABLED(CONFIG_FOO)" is true for both CONFIG_FOO=y and
> > CONFIG_FOO=m.
> >
> > This is because "CONFIG_FOO=m" in .config does not result in "CONFIG_FOO"
> > being defined. The actual definitions are in autoconf.h, where:
> >
> > CONFIG_FOO=y results in #define CONFIG_FOO 1
> > CONFIG_FOO=m results in #define CONFIG_FOO_MODULE 1
> >
> > Signed-off-by: Bjorn Helgaas <[email protected]>
>
> Acked-by: Randy Dunlap <[email protected]>
>



Applied to linux-kbuild. Thanks.




> Thanks.
>
> > ---
> > include/linux/kconfig.h | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
> > index cc8fa109cfa3..20d1079e92b4 100644
> > --- a/include/linux/kconfig.h
> > +++ b/include/linux/kconfig.h
> > @@ -51,7 +51,8 @@
> >
> > /*
> > * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
> > - * otherwise.
> > + * otherwise. CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
> > + * autoconf.h.
> > */
> > #define IS_MODULE(option) __is_defined(option##_MODULE)
> >
> > @@ -66,7 +67,8 @@
> >
> > /*
> > * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
> > - * 0 otherwise.
> > + * 0 otherwise. Note that CONFIG_FOO=y results in "#define CONFIG_FOO 1" in
> > + * autoconf.h, while CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1".
> > */
> > #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
> >
> >
>
>
> --
> ~Randy
>


--
Best Regards
Masahiro Yamada