Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1492106 > unrolled thread
| Started by | Bjorn Helgaas <bhelgaas@google.com> |
|---|---|
| First post | 2016-09-27 21:10 +0200 |
| Last post | 2016-09-27 22:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] CodingStyle: Expand IS_ENABLED() documentation Bjorn Helgaas <bhelgaas@google.com> - 2016-09-27 21:10 +0200
Re: [PATCH] CodingStyle: Expand IS_ENABLED() documentation Paul Bolle <pebolle@tiscali.nl> - 2016-09-27 21:40 +0200
Re: [PATCH] CodingStyle: Expand IS_ENABLED() documentation Bjorn Helgaas <helgaas@kernel.org> - 2016-09-27 22:40 +0200
| From | Bjorn Helgaas <bhelgaas@google.com> |
|---|---|
| Date | 2016-09-27 21:10 +0200 |
| Subject | [PATCH] CodingStyle: Expand IS_ENABLED() documentation |
| Message-ID | <sm5Vo-4Z0-23@gated-at.bofh.it> |
CodingStyle recommends IS_ENABLED(CONFIG_FOO) over #ifdef. Add an example of the #ifdef, since it's not completely obvious that in many cases the #ifdef needs to test both CONFIG_FOO and CONFIG_FOO_MODULE. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> --- Documentation/CodingStyle | 15 +++++++++++++-- include/linux/kconfig.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index a096836..b3e9743 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle @@ -911,8 +911,19 @@ The compiler will constant-fold the conditional away, and include or exclude the block of code just as with an #ifdef, so this will not add any runtime overhead. However, this approach still allows the C compiler to see the code inside the block, and check it for correctness (syntax, types, symbol -references, etc). Thus, you still have to use an #ifdef if the code inside the -block references symbols that will not exist if the condition is not met. +references, etc). + +Because the compiler processes the block, you have to use an #ifdef instead +of IS_ENABLED() when code inside the block references symbols that will not +exist if the condition is not met. Different CONFIG_FOO autoconf.h symbols +are generated for modular Kconfig options than for builtin ones, so you +need "#if defined(CONFIG_FOO) || defined(CONFIG_FOO_MODULE)" if FOO can be +a module: + + .config include/generated/autoconf.h + ------------ ---------------------------- + CONFIG_FOO=y #define CONFIG_FOO 1 + CONFIG_FOO=m #define CONFIG_FOO_MODULE 1 At the end of any non-trivial #if or #ifdef block (more than a few lines), place a comment after the #endif on the same line, noting the conditional diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h index 15ec117..51a5f66 100644 --- a/include/linux/kconfig.h +++ b/include/linux/kconfig.h @@ -60,7 +60,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))
[toc] | [next] | [standalone]
| From | Paul Bolle <pebolle@tiscali.nl> |
|---|---|
| Date | 2016-09-27 21:40 +0200 |
| Message-ID | <sm6oq-58G-27@gated-at.bofh.it> |
| In reply to | #1492106 |
On Tue, 2016-09-27 at 14:08 -0500, Bjorn Helgaas wrote: > --- a/Documentation/CodingStyle > +++ b/Documentation/CodingStyle > +Because the compiler processes the block, you have to use an #ifdef instead > +of IS_ENABLED() when code inside the block references symbols that will not > +exist if the condition is not met. Different CONFIG_FOO autoconf.h symbols > +are generated for modular Kconfig options than for builtin ones, so you > +need "#if defined(CONFIG_FOO) || defined(CONFIG_FOO_MODULE)" Isn't that equivalent to "#if IS_ENABLED(CONFIG_FOO)"? > if FOO can be > +a module: > + > + .config include/generated/autoconf.h > + ------------ ---------------------------- > + CONFIG_FOO=y #define CONFIG_FOO 1 > + CONFIG_FOO=m #define CONFIG_FOO_MODULE 1 Paul Bolle
[toc] | [prev] | [next] | [standalone]
| From | Bjorn Helgaas <helgaas@kernel.org> |
|---|---|
| Date | 2016-09-27 22:40 +0200 |
| Message-ID | <sm7ku-5JY-17@gated-at.bofh.it> |
| In reply to | #1492125 |
On Tue, Sep 27, 2016 at 09:32:08PM +0200, Paul Bolle wrote: > On Tue, 2016-09-27 at 14:08 -0500, Bjorn Helgaas wrote: > > > --- a/Documentation/CodingStyle > > +++ b/Documentation/CodingStyle > > > +Because the compiler processes the block, you have to use an #ifdef instead > > +of IS_ENABLED() when code inside the block references symbols that will not > > +exist if the condition is not met. Different CONFIG_FOO autoconf.h symbols > > +are generated for modular Kconfig options than for builtin ones, so you > > +need "#if defined(CONFIG_FOO) || defined(CONFIG_FOO_MODULE)" > > Isn't that equivalent to "#if IS_ENABLED(CONFIG_FOO)"? Yep, I think so. Sigh. I'll look again. Maybe what's already there can't be improved.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web