Skip to content

Commit 9059a34

Browse files
Nicolas Pitremasahir0y
authored andcommitted
kconfig: fix relational operators for bool and tristate symbols
Since commit 31847b6 ("kconfig: allow use of relations other than (in)equality") it is possible to use relational operators in Kconfig statements. However, those operators give unexpected results when applied to bool/tristate values: (n < y) = y (correct) (m < y) = y (correct) (n < m) = n (wrong) This happens because relational operators process bool and tristate symbols as strings and m sorts before n. It makes little sense to do a lexicographical compare on bool and tristate values though. Documentation/kbuild/kconfig-language.txt states that expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2 respectively for calculations). Let's make it so for relational comparisons with bool/tristate expressions as well and document them. If at least one symbol is an actual string then the lexicographical compare works just as before. Signed-off-by: Nicolas Pitre <nico@linaro.org> Acked-by: Randy Dunlap <rdunlap@infradead.org> Tested-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent cfe17c9 commit 9059a34

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎Documentation/kbuild/kconfig-language.txt‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,14 @@ module state. Dependency expressions have the following syntax:
200200
<expr> ::= <symbol> (1)
201201
<symbol> '=' <symbol> (2)
202202
<symbol> '!=' <symbol> (3)
203-
'(' <expr> ')' (4)
204-
'!' <expr> (5)
205-
<expr> '&&' <expr> (6)
206-
<expr> '||' <expr> (7)
203+
<symbol1> '<' <symbol2> (4)
204+
<symbol1> '>' <symbol2> (4)
205+
<symbol1> '<=' <symbol2> (4)
206+
<symbol1> '>=' <symbol2> (4)
207+
'(' <expr> ')' (5)
208+
'!' <expr> (6)
209+
<expr> '&&' <expr> (7)
210+
<expr> '||' <expr> (8)
207211

208212
Expressions are listed in decreasing order of precedence.
209213

@@ -214,10 +218,13 @@ Expressions are listed in decreasing order of precedence.
214218
otherwise 'n'.
215219
(3) If the values of both symbols are equal, it returns 'n',
216220
otherwise 'y'.
217-
(4) Returns the value of the expression. Used to override precedence.
218-
(5) Returns the result of (2-/expr/).
219-
(6) Returns the result of min(/expr/, /expr/).
220-
(7) Returns the result of max(/expr/, /expr/).
221+
(4) If value of <symbol1> is respectively lower, greater, lower-or-equal,
222+
or greater-or-equal than value of <symbol2>, it returns 'y',
223+
otherwise 'n'.
224+
(5) Returns the value of the expression. Used to override precedence.
225+
(6) Returns the result of (2-/expr/).
226+
(7) Returns the result of min(/expr/, /expr/).
227+
(8) Returns the result of max(/expr/, /expr/).
221228

222229
An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
223230
respectively for calculations). A menu entry becomes visible when its

‎scripts/kconfig/expr.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,10 @@ static enum string_value_kind expr_parse_string(const char *str,
893893
switch (type) {
894894
case S_BOOLEAN:
895895
case S_TRISTATE:
896-
return k_string;
896+
val->s = !strcmp(str, "n") ? 0 :
897+
!strcmp(str, "m") ? 1 :
898+
!strcmp(str, "y") ? 2 : -1;
899+
return k_signed;
897900
case S_INT:
898901
val->s = strtoll(str, &tail, 10);
899902
kind = k_signed;

0 commit comments

Comments
 (0)