mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bhelgaas@google.com>
To: Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: [PATCH] CodingStyle: Expand IS_ENABLED() documentation
Date: Tue, 27 Sep 2016 14:08:02 -0500	[thread overview]
Message-ID: <20160927190802.13636.10320.stgit@bhelgaas-glaptop2.roam.corp.google.com> (raw)

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))
 

             reply	other threads:[~2016-09-27 19:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27 19:08 Bjorn Helgaas [this message]
2016-09-27 19:32 ` Paul Bolle
2016-09-27 20:32   ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160927190802.13636.10320.stgit@bhelgaas-glaptop2.roam.corp.google.com \
    --to=bhelgaas@google.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®