Skip to contentSkip to conversation

kconfig.h: explain IS_MODULE(), IS_ENABLED()

PATCH In review Bjorn Helgaas 3 participants 3 messages Jun 1, 2021 – Jun 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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
---
 include/linux/kconfig.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/kconfig.h +4 -2
index cc8fa109cfa3..20d1079e92b4 100644
@@ -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))
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Bjorn Helgaas

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.

Quoted 7 lines

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

Thanks.

Quoted 29 lines
---
 include/linux/kconfig.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/kconfig.h +4 -2
index cc8fa109cfa3..20d1079e92b4 100644
@@ -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))
 
Signature · 1 line
~Randy
#2 lore raw
Quoted 14 lines · Randy Dunlap
Quoted 12 lines · Bjorn Helgaas

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:

Quoted 7 lines
Quoted 4 lines
  CONFIG_FOO=y   results in   #define CONFIG_FOO 1
  CONFIG_FOO=m   results in   #define CONFIG_FOO_MODULE 1

Applied to linux-kbuild. Thanks.

Quoted 36 lines

Thanks.

Quoted 20 lines
---
 include/linux/kconfig.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/kconfig.h +2 -1
index cc8fa109cfa3..20d1079e92b4 100644
@@ -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)
 

include/linux/kconfig.h line 74

Quoted 9 lines
include/linux/kconfig.h +2 -1
@@ -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

Signature · 2 lines
Best Regards
Masahiro Yamada