Skip to contentSkip to conversation

kconfig: Add implicit CONFIG_ prefix to IS_ENABLED() and co

RFC PATCH NAK Peter Zijlstra 7 participants 8 messages Jun 28, 2022 – Jun 29, 2022

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 kconfig: Add implicit CONFIG_ prefix to IS_ENABLED() and co

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

---

With this on, something like:

for i in IS_BUILTIN IS_MODULE IS_REACHABLE IS_ENABLED; do

	git grep -wl $i | while read file;
	do
		sed -ie "s/${i}(CONFIG_/${i}(/g" $file;
        done;

done

can be used to convert all existing instance. Allowing, after time passes, to remove the CONFIG_ usage if so desired.

---
 tools/include/linux/kconfig.h   |    7 ++++---
 include/linux/kconfig.h         |    7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/kconfig.h +4 -3
@@ -38,6 +38,7 @@
  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
  * the last step cherry picks the 2nd arg, we get a zero.
  */
+#define _is_defined(x)			__or(__is_defined(x), __is_defined(CONFIG_##x))
 #define __is_defined(x)			___is_defined(x)
 #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
 #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
@@ -47,14 +48,14 @@
  * otherwise. For boolean options, this is equivalent to
  * IS_ENABLED(CONFIG_FOO).
  */
-#define IS_BUILTIN(option) __is_defined(option)
+#define IS_BUILTIN(option) _is_defined(option)
 
 /*
  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
  * otherwise.  CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
  * autoconf.h.
  */
-#define IS_MODULE(option) __is_defined(option##_MODULE)
+#define IS_MODULE(option) _is_defined(option##_MODULE)
 
 /*
  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
@@ -63,7 +64,7 @@
  * built-in code when CONFIG_FOO is set to 'm'.
  */
 #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
-				__and(IS_MODULE(option), __is_defined(MODULE)))
+				__and(IS_MODULE(option), _is_defined(MODULE)))
 
 /*
  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
tools/include/linux/kconfig.h +4 -3
@@ -32,6 +32,7 @@
  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
  * the last step cherry picks the 2nd arg, we get a zero.
  */
+#define _is_defined(x)			__or(__is_defined(x), __is_defined(CONFIG_##x))
 #define __is_defined(x)			___is_defined(x)
 #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
 #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
@@ -41,13 +42,13 @@
  * otherwise. For boolean options, this is equivalent to
  * IS_ENABLED(CONFIG_FOO).
  */
-#define IS_BUILTIN(option) __is_defined(option)
+#define IS_BUILTIN(option) _is_defined(option)
 
 /*
  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
  * otherwise.
  */
-#define IS_MODULE(option) __is_defined(option##_MODULE)
+#define IS_MODULE(option) _is_defined(option##_MODULE)
 
 /*
  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
@@ -56,7 +57,7 @@
  * built-in code when CONFIG_FOO is set to 'm'.
  */
 #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
-				__and(IS_MODULE(option), __is_defined(MODULE)))
+				__and(IS_MODULE(option), _is_defined(MODULE)))
 
 /*
  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

FWIW:

Quoted 92 lines

---

With this on, something like:

for i in IS_BUILTIN IS_MODULE IS_REACHABLE IS_ENABLED; do

	git grep -wl $i | while read file;
	do
		sed -ie "s/${i}(CONFIG_/${i}(/g" $file;
      done;

done

can be used to convert all existing instance. Allowing, after time passes, to remove the CONFIG_ usage if so desired.

---
 tools/include/linux/kconfig.h   |    7 ++++---
 include/linux/kconfig.h         |    7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/kconfig.h +4 -3
@@ -38,6 +38,7 @@
  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
  * the last step cherry picks the 2nd arg, we get a zero.
  */
+#define _is_defined(x)			__or(__is_defined(x), __is_defined(CONFIG_##x))
 #define __is_defined(x)			___is_defined(x)
 #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
 #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
@@ -47,14 +48,14 @@
  * otherwise. For boolean options, this is equivalent to
  * IS_ENABLED(CONFIG_FOO).
  */
-#define IS_BUILTIN(option) __is_defined(option)
+#define IS_BUILTIN(option) _is_defined(option)
 
 /*
  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
  * otherwise.  CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
  * autoconf.h.
  */
-#define IS_MODULE(option) __is_defined(option##_MODULE)
+#define IS_MODULE(option) _is_defined(option##_MODULE)
 
 /*
  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
@@ -63,7 +64,7 @@
  * built-in code when CONFIG_FOO is set to 'm'.
  */
 #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
-				__and(IS_MODULE(option), __is_defined(MODULE)))
+				__and(IS_MODULE(option), _is_defined(MODULE)))
 
 /*
  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
tools/include/linux/kconfig.h +4 -3
@@ -32,6 +32,7 @@
  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
  * the last step cherry picks the 2nd arg, we get a zero.
  */
+#define _is_defined(x)			__or(__is_defined(x), __is_defined(CONFIG_##x))
 #define __is_defined(x)			___is_defined(x)
 #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
 #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
@@ -41,13 +42,13 @@
  * otherwise. For boolean options, this is equivalent to
  * IS_ENABLED(CONFIG_FOO).
  */
-#define IS_BUILTIN(option) __is_defined(option)
+#define IS_BUILTIN(option) _is_defined(option)
 
 /*
  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
  * otherwise.
  */
-#define IS_MODULE(option) __is_defined(option##_MODULE)
+#define IS_MODULE(option) _is_defined(option##_MODULE)
 
 /*
  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
@@ -56,7 +57,7 @@
  * built-in code when CONFIG_FOO is set to 'm'.
  */
 #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
-				__and(IS_MODULE(option), __is_defined(MODULE)))
+				__and(IS_MODULE(option), _is_defined(MODULE)))
 
 /*
  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw
In reply to Peter Zijlstra
Quoted 6 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

I'd prefer to keep the more verbose usage, mainly because it makes it easier to grep for a symbol. If today you do 'git grep CONFIG_PM_SLEEP', you find all instances in Makefile, in #ifdef and in IS_ENABLED(), though not the references in Kconfig language, which leave out the prefix.

If we remove the prefix for IS_ENABLED(), the same grep fails to get all the results, while searching for the substring without the CONFIG_ prefix can end up finding false-positives by finding longer strings (e.g. CONFIG_DEBUG_STACKOVERFLOW vs CONFIG_HAVE_DEBUG_STACKOVERFLOW).

Arnd

#3 lore raw
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

Quoted 6 lines
Quoted 1 line

I'd prefer to keep the more verbose usage, mainly because it makes it easier to grep for a symbol. If today you do 'git grep CONFIG_PM_SLEEP', you find all instances in Makefile, in #ifdef and in IS_ENABLED(), though not the references in Kconfig language, which leave out the prefix.

Which is why I never grep for the CONFIG_ thing to begin with, it misses the Kconfig site.

Quoted 5 lines

If we remove the prefix for IS_ENABLED(), the same grep fails to get all the results, while searching for the substring without the CONFIG_ prefix can end up finding false-positives by finding longer strings (e.g. CONFIG_DEBUG_STACKOVERFLOW vs CONFIG_HAVE_DEBUG_STACKOVERFLOW).

Me being used to that doesn't consider that a real issue :-) I'd much rather have the somewhat shorter IS_ENABLED() things.

#4 lore raw
Quoted 18 lines · Peter Zijlstra
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

Quoted 6 lines
Quoted 1 line

I'd prefer to keep the more verbose usage, mainly because it makes it easier to grep for a symbol. If today you do 'git grep CONFIG_PM_SLEEP', you find all instances in Makefile, in #ifdef and in IS_ENABLED(), though not the references in Kconfig language, which leave out the prefix.

Which is why I never grep for the CONFIG_ thing to begin with, it misses the Kconfig site.

Quoted 8 lines
Quoted 5 lines

If we remove the prefix for IS_ENABLED(), the same grep fails to get all the results, while searching for the substring without the CONFIG_ prefix can end up finding false-positives by finding longer strings (e.g. CONFIG_DEBUG_STACKOVERFLOW vs CONFIG_HAVE_DEBUG_STACKOVERFLOW).

Me being used to that doesn't consider that a real issue :-) I'd much rather have the somewhat shorter IS_ENABLED() things.

One more thing worth mentioning, this patch does
not even work correctly.

scripts/basic/fixdep.c searches for CONFIG_ prefix. This works nicely, and there is no reason to lose this simplicity.

NACK.

Signature · 2 lines
Best Regards
Masahiro Yamada
#5 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

Quoted 6 lines
Quoted 1 line

I'd prefer to keep the more verbose usage, mainly because it makes it easier to grep for a symbol. If today you do 'git grep CONFIG_PM_SLEEP', you find all instances in Makefile, in #ifdef and in IS_ENABLED(), though not the references in Kconfig language, which leave out the prefix.

Agreed.

Also, having CONFIG_ added implicitly requires updating fixdep, and that will probably make the fixdep step somewhat more expensive - because one would still have to find all explicit CONFIG_SOMETHING (they'd still be used in ifdefs, and the int and string options directly in code), but in addition also grep for IS_ENABLED, IS_BUILTIN, IS_MODULE.

Rasmus

#6 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · [Re: [RFC][PATCH] kconfig: Add implicit CONFIG_ prefix to IS_ENABLED() and co]…
Quoted 5 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

Quoted 6 lines
Quoted 1 line

I'd prefer to keep the more verbose usage, mainly because it makes it easier to grep for a symbol. If today you do 'git grep CONFIG_PM_SLEEP', you find all instances in Makefile, in #ifdef and in IS_ENABLED(), though not the references in Kconfig language, which leave out the prefix.

TL;DR - me too.

I confess that I do the same thing - I grep for CONFIG_FOO to find the consumers, and "config FOO" to find the provider.

So while I can appreciate the value of removing verbosity, this will impact workflows of average people out there.

Doing a grep for "PCI" is practically worthless. Having to grep for both CONFIG_PCI and IS_ENABLED\(PCI will inevitably annoy people when they realize they missed a code path needing an update because they only searched for the former.

Paul.
--

Quoted 8 lines

If we remove the prefix for IS_ENABLED(), the same grep fails to get all the results, while searching for the substring without the CONFIG_ prefix can end up finding false-positives by finding longer strings (e.g. CONFIG_DEBUG_STACKOVERFLOW vs CONFIG_HAVE_DEBUG_STACKOVERFLOW).

Arnd

#7 lore raw
In reply to Peter Zijlstra
Quoted 4 lines · Peter Zijlstra

Since IS_ENABLED() (and friends) are clearly meant to be used on CONFIG_foo symbols and IS_ENABLED(CONFIG_ is so long and almost an tautology, allow the more compact usage of: IS_ENABLED(foo).

Eww. Please don't mess up grepability for saving a few characters of typing.