From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752141AbdLFPkL (ORCPT ); Wed, 6 Dec 2017 10:40:11 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35214 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752020AbdLFPkJ (ORCPT ); Wed, 6 Dec 2017 10:40:09 -0500 X-Google-Smtp-Source: AGs4zMaZIb5XS1oja6jDFsMJM+MJBZRF8tP7OU9J74cSM8HUySc9FywGio6NzGpTFaOOnqZdapo9GA== Date: Wed, 6 Dec 2017 10:40:06 -0500 (EST) From: Nicolas Pitre To: Masahiro Yamada , Michal Marek , Jan Beulich cc: Arnd Bergmann , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kconfig: fix relational operators for bool and tristate symbols In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping. On Thu, 16 Nov 2017, Nicolas Pitre wrote: > 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 > > diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt > index 262722d886..c4a293a03c 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: > ::= (1) > '=' (2) > '!=' (3) > - '(' ')' (4) > - '!' (5) > - '&&' (6) > - '||' (7) > + '<' (4) > + '>' (4) > + '<=' (4) > + '>=' (4) > + '(' ')' (5) > + '!' (6) > + '&&' (7) > + '||' (8) > > Expressions are listed in decreasing order of precedence. > > @@ -214,10 +218,13 @@ Expressions are listed in decreasing order of precedence. > otherwise 'n'. > (3) If the values of both symbols are equal, it returns 'n', > otherwise 'y'. > -(4) Returns the value of the expression. Used to override precedence. > -(5) Returns the result of (2-/expr/). > -(6) Returns the result of min(/expr/, /expr/). > -(7) Returns the result of max(/expr/, /expr/). > +(4) If value of is respectively lower, greater, lower-or-equal, > + or greater-or-equal than value of , it returns 'y', > + otherwise 'n'. > +(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 > respectively for calculations). A menu entry becomes visible when its > diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c > index cbf4996dd9..8cee597d33 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, > switch (type) { > case S_BOOLEAN: > 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: > val->s = strtoll(str, &tail, 10); > kind = k_signed; >