diff mbox series

[2/2] kconfig: default to zero if int/hex symbol lacks default property

Message ID 20231125163559.824210-2-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/2] kconfig: remove unneeded symbol_empty variable | expand

Commit Message

Masahiro Yamada Nov. 25, 2023, 4:35 p.m. UTC
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(-)

Comments

Yoann Congal Nov. 25, 2023, 11:10 p.m. UTC | #1
Le 25/11/2023 à 17:35, Masahiro Yamada a écrit :
> 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>

Thanks! It does fix our problem.

Reviewed-by: Yoann Congal <yoann.congal@smile.fr>

> ---
> 
>  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)
diff mbox series

Patch

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)