diff mbox series

treewide: Change CONFIG_BASE_SMALL to bool type

Message ID 20240126163032.1613731-1-yoann.congal@smile.fr
State New
Headers show
Series treewide: Change CONFIG_BASE_SMALL to bool type | expand

Commit Message

Yoann Congal Jan. 26, 2024, 4:30 p.m. UTC
CONFIG_BASE_SMALL is currently a type int but is only used as a boolean:
CONFIG_BASE_SMALL == 0 vs CONFIG_BASE_SMALL != 0.

So change it to the more logical bool type.

Furthermore, recent kconfig changes (see Fixes: tags) revealed that using
  config SOMETHING
     default "some value" if X
does not work as expected if X is not of type bool.

CONFIG_BASE_SMALL is used that way in init/Kconfig:
  config LOG_CPU_MAX_BUF_SHIFT
  	default 12 if !BASE_SMALL
  	default 0 if BASE_SMALL

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/all/CAMuHMdWm6u1wX7efZQf=2XUAHascps76YQac6rdnQGhc8nop_Q@mail.gmail.com/
Fixes: 6262afa10ef7 ("kconfig: default to zero if int/hex symbol lacks default property")
Fixes: 4e244c10eab3 ("kconfig: remove unneeded symbol_empty variable")

---
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Jiri Slaby <jirislaby@kernel.org>
CC: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
CC: Matthew Wilcox <willy@infradead.org>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Darren Hart <dvhart@infradead.org>
CC: Davidlohr Bueso <dave@stgolabs.net>
CC: "André Almeida" <andrealmeid@igalia.com>
CC: Masahiro Yamada <masahiroy@kernel.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
CC: linux-serial@vger.kernel.org
CC: linux-fsdevel@vger.kernel.org
CC: linux-kbuild@vger.kernel.org
---
 arch/x86/include/asm/mpspec.h | 2 +-
 drivers/tty/vt/vc_screen.c    | 2 +-
 include/linux/threads.h       | 4 ++--
 include/linux/udp.h           | 2 +-
 include/linux/xarray.h        | 2 +-
 init/Kconfig                  | 6 +++---
 kernel/futex/core.c           | 2 +-
 kernel/user.c                 | 2 +-
 8 files changed, 11 insertions(+), 11 deletions(-)

Comments

Masahiro Yamada Jan. 26, 2024, 7:28 p.m. UTC | #1
(+CC: Luis R. Rodriguez, author of 23b2899f7f194)


On Sat, Jan 27, 2024 at 1:30 AM Yoann Congal <yoann.congal@smile.fr> wrote:
>
> CONFIG_BASE_SMALL is currently a type int but is only used as a boolean:
> CONFIG_BASE_SMALL == 0 vs CONFIG_BASE_SMALL != 0.
>
> So change it to the more logical bool type.
>
> Furthermore, recent kconfig changes (see Fixes: tags) revealed that using

Seeing the Fixes tage does not reveal this issue.

The discussion in Closes: thread explains the issue.



>   config SOMETHING
>      default "some value" if X
> does not work as expected if X is not of type bool.
>
> CONFIG_BASE_SMALL is used that way in init/Kconfig:
>   config LOG_CPU_MAX_BUF_SHIFT
>         default 12 if !BASE_SMALL
>         default 0 if BASE_SMALL


Or, an even cleaner way is to remove BASE_SMALL because it is
the same as !BASE_FULL.


    config LOG_CPU_MAX_BUF_SHIFT
           default 12 if BASE_FULL
           default 0

You also need to invert the logic in C as well.



Perhaps, it might be worth mentioning this changes
CONFIG_LOG_CPU_MAX_BUF_SHIFT=12 to
CONFIG_LOG_CPU_MAX_BUF_SHIFT=0 for some defconfigs,
but that will not be a big impact due to this code:

 /* by default this will only continue through for large > 64 CPUs */
 if (cpu_extra <= __LOG_BUF_LEN / 2)
         return;




>
> Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Closes: https://lore.kernel.org/all/CAMuHMdWm6u1wX7efZQf=2XUAHascps76YQac6rdnQGhc8nop_Q@mail.gmail.com/
> Fixes: 6262afa10ef7 ("kconfig: default to zero if int/hex symbol lacks default property")

This tag is not relevant.


> Fixes: 4e244c10eab3 ("kconfig: remove unneeded symbol_empty variable")

This is correct.






> ---
> CC: Thomas Gleixner <tglx@linutronix.de>
> CC: Ingo Molnar <mingo@redhat.com>
> CC: Borislav Petkov <bp@alien8.de>
> CC: Dave Hansen <dave.hansen@linux.intel.com>
> CC: "H. Peter Anvin" <hpa@zytor.com>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> CC: Jiri Slaby <jirislaby@kernel.org>
> CC: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> CC: Matthew Wilcox <willy@infradead.org>
> CC: Peter Zijlstra <peterz@infradead.org>
> CC: Darren Hart <dvhart@infradead.org>
> CC: Davidlohr Bueso <dave@stgolabs.net>
> CC: "André Almeida" <andrealmeid@igalia.com>
> CC: Masahiro Yamada <masahiroy@kernel.org>
> CC: x86@kernel.org
> CC: linux-kernel@vger.kernel.org
> CC: linux-serial@vger.kernel.org
> CC: linux-fsdevel@vger.kernel.org
> CC: linux-kbuild@vger.kernel.org
> ---
>  arch/x86/include/asm/mpspec.h | 2 +-
>  drivers/tty/vt/vc_screen.c    | 2 +-
>  include/linux/threads.h       | 4 ++--
>  include/linux/udp.h           | 2 +-
>  include/linux/xarray.h        | 2 +-
>  init/Kconfig                  | 6 +++---
>  kernel/futex/core.c           | 2 +-
>  kernel/user.c                 | 2 +-
>  8 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
> index 4b0f98a8d338d..ebe4b6121b698 100644
> --- a/arch/x86/include/asm/mpspec.h
> +++ b/arch/x86/include/asm/mpspec.h
> @@ -15,7 +15,7 @@ extern int pic_mode;
>   * Summit or generic (i.e. installer) kernels need lots of bus entries.
>   * Maximum 256 PCI busses, plus 1 ISA bus in each of 4 cabinets.
>   */
> -#if CONFIG_BASE_SMALL == 0
> +#ifndef CONFIG_BASE_SMALL
>  # define MAX_MP_BUSSES         260
>  #else
>  # define MAX_MP_BUSSES         32
> diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
> index 67e2cb7c96eec..da33c6c4691c0 100644
> --- a/drivers/tty/vt/vc_screen.c
> +++ b/drivers/tty/vt/vc_screen.c
> @@ -51,7 +51,7 @@
>  #include <asm/unaligned.h>
>
>  #define HEADER_SIZE    4u
> -#define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE)
> +#define CON_BUF_SIZE (IS_ENABLED(CONFIG_BASE_SMALL) ? 256 : PAGE_SIZE)
>
>  /*
>   * Our minor space:
> diff --git a/include/linux/threads.h b/include/linux/threads.h
> index c34173e6c5f18..1674a471b0b4c 100644
> --- a/include/linux/threads.h
> +++ b/include/linux/threads.h
> @@ -25,13 +25,13 @@
>  /*
>   * This controls the default maximum pid allocated to a process
>   */
> -#define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000)
> +#define PID_MAX_DEFAULT (IS_ENABLED(CONFIG_BASE_SMALL) ? 0x1000 : 0x8000)
>
>  /*
>   * A maximum of 4 million PIDs should be enough for a while.
>   * [NOTE: PID/TIDs are limited to 2^30 ~= 1 billion, see FUTEX_TID_MASK.]
>   */
> -#define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : \
> +#define PID_MAX_LIMIT (IS_ENABLED(CONFIG_BASE_SMALL) ? PAGE_SIZE * 8 : \
>         (sizeof(long) > 4 ? 4 * 1024 * 1024 : PID_MAX_DEFAULT))
>
>  /*
> diff --git a/include/linux/udp.h b/include/linux/udp.h
> index d04188714dca1..b456417fb4515 100644
> --- a/include/linux/udp.h
> +++ b/include/linux/udp.h
> @@ -24,7 +24,7 @@ static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
>  }
>
>  #define UDP_HTABLE_SIZE_MIN_PERNET     128
> -#define UDP_HTABLE_SIZE_MIN            (CONFIG_BASE_SMALL ? 128 : 256)
> +#define UDP_HTABLE_SIZE_MIN            (IS_ENABLED(CONFIG_BASE_SMALL) ? 128 : 256)
>  #define UDP_HTABLE_SIZE_MAX            65536
>
>  static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
> diff --git a/include/linux/xarray.h b/include/linux/xarray.h
> index cb571dfcf4b16..3f81ee5f9fb9c 100644
> --- a/include/linux/xarray.h
> +++ b/include/linux/xarray.h
> @@ -1141,7 +1141,7 @@ static inline void xa_release(struct xarray *xa, unsigned long index)
>   * doubled the number of slots per node, we'd get only 3 nodes per 4kB page.
>   */
>  #ifndef XA_CHUNK_SHIFT
> -#define XA_CHUNK_SHIFT         (CONFIG_BASE_SMALL ? 4 : 6)
> +#define XA_CHUNK_SHIFT         (IS_ENABLED(CONFIG_BASE_SMALL) ? 4 : 6)
>  #endif
>  #define XA_CHUNK_SIZE          (1UL << XA_CHUNK_SHIFT)
>  #define XA_CHUNK_MASK          (XA_CHUNK_SIZE - 1)
> diff --git a/init/Kconfig b/init/Kconfig
> index 8d4e836e1b6b1..766a7ac8c5ea4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -1941,9 +1941,9 @@ config RT_MUTEXES
>         default y if PREEMPT_RT
>
>  config BASE_SMALL
> -       int
> -       default 0 if BASE_FULL
> -       default 1 if !BASE_FULL
> +       bool
> +       default n if BASE_FULL
> +       default y if !BASE_FULL
>
>  config MODULE_SIG_FORMAT
>         def_bool n
> diff --git a/kernel/futex/core.c b/kernel/futex/core.c
> index e0e853412c158..5f7aa4fc2f9ee 100644
> --- a/kernel/futex/core.c
> +++ b/kernel/futex/core.c
> @@ -1141,7 +1141,7 @@ static int __init futex_init(void)
>         unsigned int futex_shift;
>         unsigned long i;
>
> -#if CONFIG_BASE_SMALL
> +#ifdef CONFIG_BASE_SMALL
>         futex_hashsize = 16;
>  #else
>         futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
> diff --git a/kernel/user.c b/kernel/user.c
> index 03cedc366dc9e..aa1162deafe49 100644
> --- a/kernel/user.c
> +++ b/kernel/user.c
> @@ -88,7 +88,7 @@ EXPORT_SYMBOL_GPL(init_user_ns);
>   * when changing user ID's (ie setuid() and friends).
>   */
>
> -#define UIDHASH_BITS   (CONFIG_BASE_SMALL ? 3 : 7)
> +#define UIDHASH_BITS   (IS_ENABLED(CONFIG_BASE_SMALL) ? 3 : 7)
>  #define UIDHASH_SZ     (1 << UIDHASH_BITS)
>  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
>  #define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
> --
> 2.39.2
>
Masahiro Yamada Jan. 26, 2024, 7:41 p.m. UTC | #2
On Sat, Jan 27, 2024 at 4:28 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> (+CC: Luis R. Rodriguez, author of 23b2899f7f194)



Just a nit.


I think "printk:" is more suitable for the subject prefix
than "treewide:".

Thanks.
diff mbox series

Patch

diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index 4b0f98a8d338d..ebe4b6121b698 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -15,7 +15,7 @@  extern int pic_mode;
  * Summit or generic (i.e. installer) kernels need lots of bus entries.
  * Maximum 256 PCI busses, plus 1 ISA bus in each of 4 cabinets.
  */
-#if CONFIG_BASE_SMALL == 0
+#ifndef CONFIG_BASE_SMALL
 # define MAX_MP_BUSSES		260
 #else
 # define MAX_MP_BUSSES		32
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 67e2cb7c96eec..da33c6c4691c0 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -51,7 +51,7 @@ 
 #include <asm/unaligned.h>
 
 #define HEADER_SIZE	4u
-#define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE)
+#define CON_BUF_SIZE (IS_ENABLED(CONFIG_BASE_SMALL) ? 256 : PAGE_SIZE)
 
 /*
  * Our minor space:
diff --git a/include/linux/threads.h b/include/linux/threads.h
index c34173e6c5f18..1674a471b0b4c 100644
--- a/include/linux/threads.h
+++ b/include/linux/threads.h
@@ -25,13 +25,13 @@ 
 /*
  * This controls the default maximum pid allocated to a process
  */
-#define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000)
+#define PID_MAX_DEFAULT (IS_ENABLED(CONFIG_BASE_SMALL) ? 0x1000 : 0x8000)
 
 /*
  * A maximum of 4 million PIDs should be enough for a while.
  * [NOTE: PID/TIDs are limited to 2^30 ~= 1 billion, see FUTEX_TID_MASK.]
  */
-#define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : \
+#define PID_MAX_LIMIT (IS_ENABLED(CONFIG_BASE_SMALL) ? PAGE_SIZE * 8 : \
 	(sizeof(long) > 4 ? 4 * 1024 * 1024 : PID_MAX_DEFAULT))
 
 /*
diff --git a/include/linux/udp.h b/include/linux/udp.h
index d04188714dca1..b456417fb4515 100644
--- a/include/linux/udp.h
+++ b/include/linux/udp.h
@@ -24,7 +24,7 @@  static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
 }
 
 #define UDP_HTABLE_SIZE_MIN_PERNET	128
-#define UDP_HTABLE_SIZE_MIN		(CONFIG_BASE_SMALL ? 128 : 256)
+#define UDP_HTABLE_SIZE_MIN		(IS_ENABLED(CONFIG_BASE_SMALL) ? 128 : 256)
 #define UDP_HTABLE_SIZE_MAX		65536
 
 static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index cb571dfcf4b16..3f81ee5f9fb9c 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -1141,7 +1141,7 @@  static inline void xa_release(struct xarray *xa, unsigned long index)
  * doubled the number of slots per node, we'd get only 3 nodes per 4kB page.
  */
 #ifndef XA_CHUNK_SHIFT
-#define XA_CHUNK_SHIFT		(CONFIG_BASE_SMALL ? 4 : 6)
+#define XA_CHUNK_SHIFT		(IS_ENABLED(CONFIG_BASE_SMALL) ? 4 : 6)
 #endif
 #define XA_CHUNK_SIZE		(1UL << XA_CHUNK_SHIFT)
 #define XA_CHUNK_MASK		(XA_CHUNK_SIZE - 1)
diff --git a/init/Kconfig b/init/Kconfig
index 8d4e836e1b6b1..766a7ac8c5ea4 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1941,9 +1941,9 @@  config RT_MUTEXES
 	default y if PREEMPT_RT
 
 config BASE_SMALL
-	int
-	default 0 if BASE_FULL
-	default 1 if !BASE_FULL
+	bool
+	default n if BASE_FULL
+	default y if !BASE_FULL
 
 config MODULE_SIG_FORMAT
 	def_bool n
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index e0e853412c158..5f7aa4fc2f9ee 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -1141,7 +1141,7 @@  static int __init futex_init(void)
 	unsigned int futex_shift;
 	unsigned long i;
 
-#if CONFIG_BASE_SMALL
+#ifdef CONFIG_BASE_SMALL
 	futex_hashsize = 16;
 #else
 	futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
diff --git a/kernel/user.c b/kernel/user.c
index 03cedc366dc9e..aa1162deafe49 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -88,7 +88,7 @@  EXPORT_SYMBOL_GPL(init_user_ns);
  * when changing user ID's (ie setuid() and friends).
  */
 
-#define UIDHASH_BITS	(CONFIG_BASE_SMALL ? 3 : 7)
+#define UIDHASH_BITS	(IS_ENABLED(CONFIG_BASE_SMALL) ? 3 : 7)
 #define UIDHASH_SZ	(1 << UIDHASH_BITS)
 #define UIDHASH_MASK		(UIDHASH_SZ - 1)
 #define __uidhashfn(uid)	(((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)