All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kconfig: initialize sym->curr.tri to no for all symbol types again
@ 2024-01-26 13:30 Masahiro Yamada
  0 siblings, 0 replies; only message in thread
From: Masahiro Yamada @ 2024-01-26 13:30 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, Geert Uytterhoeven, Yoann Congal, Masahiro Yamada

In C programming, a non-zero value is interpreted as true, and a zero
value as false.

Kconfig has never worked like that; only 'bool' and 'tristate' symbols
are properly handled in conditionals. The other types ('int', 'hex',
'string') are always interpreted as false if used in boolean contexts.

Until commit 4e244c10eab3 ("kconfig: remove unneeded symbol_empty
variable") accidentally changed the behavior, the default of
CONFIG_LOG_CPU_MAX_BUF_SHIFT was unconditionally 12, because the 'int'
symbol 'BASE_SMALL' was evaluated as false, hence 'if !BASE_SMALL' was
always true.

You can confirm it as follows:

  $ git checkout 4e244c10eab3^

  $ make -s ARCH=x86_64 defconfig
  $ grep -e LOG_CPU_MAX_BUF_SHIFT -e BASE_SMALL -e BASE_FULL .config
  CONFIG_LOG_CPU_MAX_BUF_SHIFT=12
  CONFIG_BASE_FULL=y
  CONFIG_BASE_SMALL=0

  $ make -s ARCH=arm keystone_defconfig
  $ grep -e LOG_CPU_MAX_BUF_SHIFT -e BASE_SMALL -e BASE_FULL .config
  CONFIG_LOG_CPU_MAX_BUF_SHIFT=12
  # CONFIG_BASE_FULL is not set
  CONFIG_BASE_SMALL=1

CONFIG_LOG_CPU_MAX_BUF_SHIFT defaults to 12 irrespective of the value
of CONFIG_BASE_SMALL.

Since commit 4e244c10eab3, this is an undefined behavior because
sym_calc_value() stopped setting the sym->curr.tri field for 'int',
'hex', and 'string' symbols.

Commit 23b2899f7f19 ("printk: allow increasing the ring buffer depending
on the number of CPUs") presumably intended the following:

  config LOG_CPU_MAX_BUF_SHIFT
          int "CPU kernel log buffer size contribution (13 => 8 KB, 17 => 128KB)"
            [snip]
          default 12 if BASE_SMALL == 0
          default 0

But, the correct fixes would potentially impact multiple defconfigs,
hence they should be reviewed in each dedicated subsystem.

Restore the original behavior for now.

Fixes: 4e244c10eab3 ("kconfig: remove unneeded symbol_empty variable")
Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Closes: https://lore.kernel.org/all/CAMuHMdWm6u1wX7efZQf=2XUAHascps76YQac6rdnQGhc8nop_Q@mail.gmail.com/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/symbol.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index f615e2c1e85d..1290c6d2f8c2 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -346,6 +346,8 @@ void sym_calc_value(struct symbol *sym)
 
 	oldval = sym->curr;
 
+	newval.tri = no;
+
 	switch (sym->type) {
 	case S_INT:
 		newval.val = "0";
@@ -358,7 +360,7 @@ void sym_calc_value(struct symbol *sym)
 		break;
 	case S_BOOLEAN:
 	case S_TRISTATE:
-		newval = symbol_no.curr;
+		newval.val = "n";
 		break;
 	default:
 		sym->curr.val = sym->name;
-- 
2.40.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-26 13:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26 13:30 [PATCH] kconfig: initialize sym->curr.tri to no for all symbol types again Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.