mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	kconfig: fix relational operators for bool and tristate symbols
Since commit 31847b67be ("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>
			
			
This commit is contained in:
		
							parent
							
								
									cfe17c9bbe
								
							
						
					
					
						commit
						9059a3493e
					
				
					 2 changed files with 19 additions and 9 deletions
				
			
		| 
						 | 
					@ -200,10 +200,14 @@ module state. Dependency expressions have the following syntax:
 | 
				
			||||||
<expr> ::= <symbol>                             (1)
 | 
					<expr> ::= <symbol>                             (1)
 | 
				
			||||||
           <symbol> '=' <symbol>                (2)
 | 
					           <symbol> '=' <symbol>                (2)
 | 
				
			||||||
           <symbol> '!=' <symbol>               (3)
 | 
					           <symbol> '!=' <symbol>               (3)
 | 
				
			||||||
           '(' <expr> ')'                       (4)
 | 
					           <symbol1> '<' <symbol2>              (4)
 | 
				
			||||||
           '!' <expr>                           (5)
 | 
					           <symbol1> '>' <symbol2>              (4)
 | 
				
			||||||
           <expr> '&&' <expr>                   (6)
 | 
					           <symbol1> '<=' <symbol2>             (4)
 | 
				
			||||||
           <expr> '||' <expr>                   (7)
 | 
					           <symbol1> '>=' <symbol2>             (4)
 | 
				
			||||||
 | 
					           '(' <expr> ')'                       (5)
 | 
				
			||||||
 | 
					           '!' <expr>                           (6)
 | 
				
			||||||
 | 
					           <expr> '&&' <expr>                   (7)
 | 
				
			||||||
 | 
					           <expr> '||' <expr>                   (8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Expressions are listed in decreasing order of precedence. 
 | 
					Expressions are listed in decreasing order of precedence. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -214,10 +218,13 @@ Expressions are listed in decreasing order of precedence.
 | 
				
			||||||
    otherwise 'n'.
 | 
					    otherwise 'n'.
 | 
				
			||||||
(3) If the values of both symbols are equal, it returns 'n',
 | 
					(3) If the values of both symbols are equal, it returns 'n',
 | 
				
			||||||
    otherwise 'y'.
 | 
					    otherwise 'y'.
 | 
				
			||||||
(4) Returns the value of the expression. Used to override precedence.
 | 
					(4) If value of <symbol1> is respectively lower, greater, lower-or-equal,
 | 
				
			||||||
(5) Returns the result of (2-/expr/).
 | 
					    or greater-or-equal than value of <symbol2>, it returns 'y',
 | 
				
			||||||
(6) Returns the result of min(/expr/, /expr/).
 | 
					    otherwise 'n'.
 | 
				
			||||||
(7) Returns the result of max(/expr/, /expr/).
 | 
					(5) Returns the value of the expression. Used to override precedence.
 | 
				
			||||||
 | 
					(6) Returns the result of (2-/expr/).
 | 
				
			||||||
 | 
					(7) Returns the result of min(/expr/, /expr/).
 | 
				
			||||||
 | 
					(8) Returns the result of max(/expr/, /expr/).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
 | 
					An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
 | 
				
			||||||
respectively for calculations). A menu entry becomes visible when its
 | 
					respectively for calculations). A menu entry becomes visible when its
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -893,7 +893,10 @@ static enum string_value_kind expr_parse_string(const char *str,
 | 
				
			||||||
	switch (type) {
 | 
						switch (type) {
 | 
				
			||||||
	case S_BOOLEAN:
 | 
						case S_BOOLEAN:
 | 
				
			||||||
	case S_TRISTATE:
 | 
						case S_TRISTATE:
 | 
				
			||||||
		return k_string;
 | 
							val->s = !strcmp(str, "n") ? 0 :
 | 
				
			||||||
 | 
								 !strcmp(str, "m") ? 1 :
 | 
				
			||||||
 | 
								 !strcmp(str, "y") ? 2 : -1;
 | 
				
			||||||
 | 
							return k_signed;
 | 
				
			||||||
	case S_INT:
 | 
						case S_INT:
 | 
				
			||||||
		val->s = strtoll(str, &tail, 10);
 | 
							val->s = strtoll(str, &tail, 10);
 | 
				
			||||||
		kind = k_signed;
 | 
							kind = k_signed;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue