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: 119085 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6268222qgn; Thu, 16 Nov 2017 17:06:56 -0800 (PST) X-Google-Smtp-Source: AGs4zMYy+S8ksEKzfxov47nqOPfsve4fy2fYLmlTgr+U7W9xAJWNTGW/0szAAOubZ+ansiuC8/ys X-Received: by 10.99.4.11 with SMTP id 11mr3522647pge.123.1510880816125; Thu, 16 Nov 2017 17:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510880816; cv=none; d=google.com; s=arc-20160816; b=edlCwZ+ITxWwRzQZ5HBgwXsXX1ng2UtDl6wSCoR8DOxjWxpeK8aw0Rh0x4dsEDiSUg jh38/dqP2M8aT/BqcxZTFjZn37oK7bWFv3o1sjTNutIiP+j/UpZ1pIrq85z6ge/9losU 9IUgtLTNhC0bJKH6qXbmq2FfHrrVG87R+zeoa1kew0rhY3PwDofKfO/beOn9HxPnkqnX YPOf3hHFYOJJkjEKWzDZfbbwWvCMqRRcOUPBlSYiMQaQagYLgun6jCjmKobcm7Oqz1Gt 8ANVdIIqrDg/aYHhmIkw9lIRYCTYS4qL3ndG9rhK5M5C/u6JhM+DP6ka5l7DcIdDhj1E JJdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=p6RgUBk0VeK0Pxamb+yggNtgRXF7RhWN+gI4AFbhE4c=; b=OPMPc0adLJFN6hAQ67/rZigeU2p3J1kthjq01rB7c4j3r2W0+Z60TRhwfdGszy6BC7 fVaZ8X/PWng/5GMUrfDqprzsc8KD+daFwkBtOms2NwUuCwMHbBJMTZIrUhs2Sr4C+WID 8ptqyLux2+vYWd7i/KKnzxBrqn/9XLabQNpZ9y97LCE1zNPNcOhrIAlf3kllWgtW1+y8 aCtSqNIXRGehEJtAOuXnw5yYMlanDnwWRN/B6UlXT6gxTE4O+Hv+mHAWrqAfO8b+8Roi 9kexmdrpGEItFBcsqEoFhMibNLxqHYrQDSmTjIysLSMh0qx1RbCnNduXqZXQLphrMyti XOVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bRFcrcGb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s187si1768424pgc.532.2017.11.16.17.06.55; Thu, 16 Nov 2017 17:06:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bRFcrcGb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754354AbdKQBGy (ORCPT + 28 others); Thu, 16 Nov 2017 20:06:54 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:44551 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754270AbdKQBGl (ORCPT ); Thu, 16 Nov 2017 20:06:41 -0500 Received: by mail-qt0-f194.google.com with SMTP id h42so2294175qtk.11 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=Exyr2WDAaLDGXmG0LdL3RVVD6XrCaHYyAtGEA9TpPZdmuHBjFeubDYCPXS/1zgqptG qHZuDcsAAVepGqO2wICUv88nk1zetq+MOF0pRibUagIHi9rYDNp6ucfCn0PaGS2AglrG UU6lAaLwy0KGk0E/36O7jj0V+zOAZLRugtNhZfvc8q4v5FOTfTtPXYiVLBfKFiH+9jYl RDeiyEgv4z0OuYTjZYDyGZhhSF17nu8//VvATuSZCWbevjgGaLpvhnPp3LF38/Cym3Nl EDE0MFVOKZyQf7bmjLjV3aXrWJ+4F8Nqs4ovXANmxc/CCOSjCjDB5b32Q8cjpwecuxgZ qNmQ== X-Gm-Message-State: AJaThX7qwb3tRoAPjWdek0W7WNxh3nhmeuB0agvQBGa+sOeZtQERK+Vh E8GQg118ifxlfPlY22VXspe3oQ== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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;