From patchwork Fri Nov 17 01:06:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 10062213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 401176023A for ; Fri, 17 Nov 2017 01:06:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 344352AAFF for ; Fri, 17 Nov 2017 01:06:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28F7E2AB85; Fri, 17 Nov 2017 01:06:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CAAD2AAFF for ; Fri, 17 Nov 2017 01:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754275AbdKQBGo (ORCPT ); Thu, 16 Nov 2017 20:06:44 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:41983 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754272AbdKQBGl (ORCPT ); Thu, 16 Nov 2017 20:06:41 -0500 Received: by mail-qt0-f193.google.com with SMTP id e19so2307817qte.8 for ; Thu, 16 Nov 2017 17:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=p6RgUBk0VeK0Pxamb+yggNtgRXF7RhWN+gI4AFbhE4c=; b=bRFcrcGb+F0uV4IjGkni/Owg1Rnnmk3CB57cIRmebXvFpMUv3iafjW8g8TayRWmnbm TLqaDlD3PdWRNv4e96bCfnv1I8bbin5ibhswfCH00N+mq4/WpNWqFFsd//E8PMsGUT1f 75KdLlkEdhiAbWbap41N7AGg6gL4UM6dbwEJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=p6RgUBk0VeK0Pxamb+yggNtgRXF7RhWN+gI4AFbhE4c=; b=EJ81LVFEu9FxGo1mCXxMF1E8Qa7NqgvVXjscSG5w3uq1XvG9Di3Ge7fEycndFiFnj8 SEZ1JlA1cALvoXco62MsMh50fDWbJ3QTR/TPWiVeDeS+zMusWiTY3sY0VXyP1NcyOLq5 eMscxW2RTTe7uFD0/V9H/3ePCG0J5QdCJ1ABcexu0xAz+y5itMZMgmiFsQ/gaTa/GzlC 3BEjxZ3ZibA6+UpnXkKgY9CR/lbgv4CpTEd7iEu2WxvK2lXtLCE3V2syI5e5E7dxOwHA URQNfo7akJdBmTPAg4FloQzEU4peve2sgxJ9l3Up/7QXKF4vwJIXL0lkIx0Nv3uj3aMb kd/Q== X-Gm-Message-State: AJaThX40NG2WkuwCOdzCbFsZycR1lQBtrksVzx4bdwUyM9Xn51XABoha nfGws6zS8ciRo34rff8UuPBW/g== X-Google-Smtp-Source: AGs4zMZWTlsNZewNw1LQqudZpSkQtU9tJ1ZRMJ54B7OU8z9TVkiZZ/3a60P2e890xF6JesZYz6a6oA== X-Received: by 10.55.155.198 with SMTP id d189mr5486975qke.347.1510880800990; Thu, 16 Nov 2017 17:06:40 -0800 (PST) Received: from xanadu.home (modemcable045.234-175-137.mc.videotron.ca. [137.175.234.45]) by smtp.gmail.com with ESMTPSA id o57sm1743206qtf.53.2017.11.16.17.06.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Nov 2017 17:06:40 -0800 (PST) Date: Thu, 16 Nov 2017 20:06:39 -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: [PATCH] kconfig: fix relational operators for bool and tristate symbols Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Randy Dunlap Tested-by: Randy Dunlap --- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;