All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Yoann Congal <yoann.congal@smile.fr>,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH] kconfig: initialize sym->curr.tri to no for all symbol types again
Date: Fri, 26 Jan 2024 22:30:10 +0900	[thread overview]
Message-ID: <20240126133010.78999-1-masahiroy@kernel.org> (raw)

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


                 reply	other threads:[~2024-01-26 13:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240126133010.78999-1-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yoann.congal@smile.fr \
    /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 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.