public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] kconfig: default to zero if int/hex symbol lacks default property
Date: Sun, 26 Nov 2023 01:35:59 +0900	[thread overview]
Message-ID: <20231125163559.824210-2-masahiroy@kernel.org> (raw)
In-Reply-To: <20231125163559.824210-1-masahiroy@kernel.org>

When a default property is missing in an int or hex symbol, it defaults
to an empty string, which is not a valid symbol value.

It results in a incorrect .config, and can also lead to an infinite
loop in scripting.

Use "0" for int and "0x0" for hex as a default value.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/symbol.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index f7075d148ac7..a5a4f9153eb7 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -338,7 +338,11 @@ void sym_calc_value(struct symbol *sym)
 
 	switch (sym->type) {
 	case S_INT:
+		newval.val = "0";
+		break;
 	case S_HEX:
+		newval.val = "0x0";
+		break;
 	case S_STRING:
 		newval.val = "";
 		break;
@@ -746,14 +750,17 @@ const char *sym_get_string_default(struct symbol *sym)
 		case yes: return "y";
 		}
 	case S_INT:
+		if (!str[0])
+			str = "0";
+		break;
 	case S_HEX:
-		return str;
-	case S_STRING:
-		return str;
-	case S_UNKNOWN:
+		if (!str[0])
+			str = "0x0";
+		break;
+	default:
 		break;
 	}
-	return "";
+	return str;
 }
 
 const char *sym_get_string_value(struct symbol *sym)
-- 
2.40.1


  reply	other threads:[~2023-11-25 16:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-25 16:35 [PATCH 1/2] kconfig: remove unneeded symbol_empty variable Masahiro Yamada
2023-11-25 16:35 ` Masahiro Yamada [this message]
2023-11-25 23:10   ` [PATCH 2/2] kconfig: default to zero if int/hex symbol lacks default property Yoann Congal
2024-01-23 12:54 ` [PATCH 1/2] kconfig: remove unneeded symbol_empty variable Geert Uytterhoeven
2024-01-23 15:11   ` Yoann Congal
2024-01-24  8:09     ` Masahiro Yamada
2024-01-24  8:56       ` Yoann Congal
2024-01-24 20:12         ` Masahiro Yamada
2024-01-25 14:42           ` Yoann Congal
2024-01-26 13:20             ` Masahiro Yamada
2024-01-25 14:48           ` Geert Uytterhoeven
2024-01-24  9:52       ` Geert Uytterhoeven
2024-01-24 11:43         ` Masahiro Yamada

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=20231125163559.824210-2-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@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