diff options
author | Nicolas Pitre <nicolas.pitre@linaro.org> | 2017-11-16 20:06:39 -0500 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-01-05 12:31:23 -0500 |
commit | 9059a3493efea6492451430c7e2fa0af799a2abb (patch) | |
tree | bc3011bb806742c6b1f2f4d8b13692aebb51a844 | |
parent | cfe17c9bbe6a673fdafdab179c32b355ed447f66 (diff) |
kconfig: fix relational operators for bool and tristate symbols
Since commit 31847b67bec0 ("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>
-rw-r--r-- | Documentation/kbuild/kconfig-language.txt | 23 | ||||
-rw-r--r-- | scripts/kconfig/expr.c | 5 |
2 files changed, 19 insertions, 9 deletions
diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index 262722d8867b..c4a293a03c33 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt | |||
@@ -200,10 +200,14 @@ module state. Dependency expressions have the following syntax: | |||
200 | <expr> ::= <symbol> (1) | 200 | <expr> ::= <symbol> (1) |
201 | <symbol> '=' <symbol> (2) | 201 | <symbol> '=' <symbol> (2) |
202 | <symbol> '!=' <symbol> (3) | 202 | <symbol> '!=' <symbol> (3) |
203 | '(' <expr> ')' (4) | 203 | <symbol1> '<' <symbol2> (4) |
204 | '!' <expr> (5) | 204 | <symbol1> '>' <symbol2> (4) |
205 | <expr> '&&' <expr> (6) | 205 | <symbol1> '<=' <symbol2> (4) |
206 | <expr> '||' <expr> (7) | 206 | <symbol1> '>=' <symbol2> (4) |
207 | '(' <expr> ')' (5) | ||
208 | '!' <expr> (6) | ||
209 | <expr> '&&' <expr> (7) | ||
210 | <expr> '||' <expr> (8) | ||
207 | 211 | ||
208 | Expressions are listed in decreasing order of precedence. | 212 | Expressions are listed in decreasing order of precedence. |
209 | 213 | ||
@@ -214,10 +218,13 @@ Expressions are listed in decreasing order of precedence. | |||
214 | otherwise 'n'. | 218 | otherwise 'n'. |
215 | (3) If the values of both symbols are equal, it returns 'n', | 219 | (3) If the values of both symbols are equal, it returns 'n', |
216 | otherwise 'y'. | 220 | otherwise 'y'. |
217 | (4) Returns the value of the expression. Used to override precedence. | 221 | (4) If value of <symbol1> is respectively lower, greater, lower-or-equal, |
218 | (5) Returns the result of (2-/expr/). | 222 | or greater-or-equal than value of <symbol2>, it returns 'y', |
219 | (6) Returns the result of min(/expr/, /expr/). | 223 | otherwise 'n'. |
220 | (7) Returns the result of max(/expr/, /expr/). | 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/). | ||
221 | 228 | ||
222 | An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2 | 229 | An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2 |
223 | respectively for calculations). A menu entry becomes visible when its | 230 | respectively for calculations). A menu entry becomes visible when its |
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index cbf4996dd9c1..8cee597d33a5 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c | |||
@@ -893,7 +893,10 @@ static enum string_value_kind expr_parse_string(const char *str, | |||
893 | switch (type) { | 893 | switch (type) { |
894 | case S_BOOLEAN: | 894 | case S_BOOLEAN: |
895 | case S_TRISTATE: | 895 | 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; | ||
897 | case S_INT: | 900 | case S_INT: |
898 | val->s = strtoll(str, &tail, 10); | 901 | val->s = strtoll(str, &tail, 10); |
899 | kind = k_signed; | 902 | kind = k_signed; |