Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit aabdc96

Browse files
committed
kconfig: fix comparison to constant symbols, 'm', 'n'
Currently, comparisons to 'm' or 'n' result in incorrect output. [Test Code] config MODULES def_bool y modules config A def_tristate m config B def_bool A > n CONFIG_B is unset, while CONFIG_B=y is expected. The reason for the issue is because Kconfig compares the tristate values as strings. Currently, the .type fields in the constant symbol definitions, symbol_{yes,mod,no} are unspecified, i.e., S_UNKNOWN. When expr_calc_value() evaluates 'A > n', it checks the types of 'A' and 'n' to determine how to compare them. The left-hand side, 'A', is a tristate symbol with a value of 'm', which corresponds to a numeric value of 1. (Internally, 'y', 'm', and 'n' are represented as 2, 1, and 0, respectively.) The right-hand side, 'n', has an unknown type, so it is treated as the string "n" during the comparison. expr_calc_value() compares two values numerically only when both can have numeric values. Otherwise, they are compared as strings. symbol numeric value ASCII code ------------------------------------- y 2 0x79 m 1 0x6d n 0 0x6e 'm' is greater than 'n' if compared numerically (since 1 is greater than 0), but smaller than 'n' if compared as strings (since the ASCII code 0x6d is smaller than 0x6e). Specifying .type=S_TRISTATE for symbol_{yes,mod,no} fixes the above test code. Doing so, however, would cause a regression to the following test code. [Test Code 2] config MODULES def_bool n modules config A def_tristate n config B def_bool A = m You would get CONFIG_B=y, while CONFIG_B should not be set. The reason is because sym_get_string_value() turns 'm' into 'n' when the module feature is disabled. Consequently, expr_calc_value() evaluates 'A = n' instead of 'A = m'. This oddity has been hidden because the type of 'm' was previously S_UNKNOWN instead of S_TRISTATE. sym_get_string_value() should not tweak the string because the tristate value has already been correctly calculated. There is no reason to return the string "n" where its tristate value is mod. Fixes: 31847b6 ("kconfig: allow use of relations other than (in)equality") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent a607468 commit aabdc96

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scripts/kconfig/symbol.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414

1515
struct symbol symbol_yes = {
1616
.name = "y",
17+
.type = S_TRISTATE,
1718
.curr = { "y", yes },
1819
.menus = LIST_HEAD_INIT(symbol_yes.menus),
1920
.flags = SYMBOL_CONST|SYMBOL_VALID,
2021
};
2122

2223
struct symbol symbol_mod = {
2324
.name = "m",
25+
.type = S_TRISTATE,
2426
.curr = { "m", mod },
2527
.menus = LIST_HEAD_INIT(symbol_mod.menus),
2628
.flags = SYMBOL_CONST|SYMBOL_VALID,
2729
};
2830

2931
struct symbol symbol_no = {
3032
.name = "n",
33+
.type = S_TRISTATE,
3134
.curr = { "n", no },
3235
.menus = LIST_HEAD_INIT(symbol_no.menus),
3336
.flags = SYMBOL_CONST|SYMBOL_VALID,
@@ -820,8 +823,7 @@ const char *sym_get_string_value(struct symbol *sym)
820823
case no:
821824
return "n";
822825
case mod:
823-
sym_calc_value(modules_sym);
824-
return (modules_sym->curr.tri == no) ? "n" : "m";
826+
return "m";
825827
case yes:
826828
return "y";
827829
}

0 commit comments

Comments
 (0)