Skip to content

Commit

Permalink
kconfig: default to zero if int/hex symbol lacks default property
Browse files Browse the repository at this point in the history
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 an 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>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
  • Loading branch information
Masahiro Yamada committed Dec 3, 2023
1 parent 4e244c1 commit 6262afa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scripts/kconfig/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6262afa

Please sign in to comment.