Received: by 10.223.176.5 with SMTP id f5csp1213686wra; Wed, 7 Feb 2018 14:57:40 -0800 (PST) X-Google-Smtp-Source: AH8x225ABxb4jkoGgldvxckaf1TALdTmAhziydL2fzIhTwigboBPFDHL5jFx95yaAbWcoBy+Uvvv X-Received: by 2002:a17:902:5186:: with SMTP id y6-v6mr7346469plh.188.1518044260607; Wed, 07 Feb 2018 14:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518044260; cv=none; d=google.com; s=arc-20160816; b=VbWcn8NF9uO5IHuuJaa1EuKXjRuYC6n9a25sEr1wieIAZizV1qHnBoChtnBqGcTEUQ MPjgBadK9kLxdk3CqJiWiHabJP6l+YmTMXa4WM+CVvbvfKpEK73JGpPTXcmaTlPpq6rT OvZ33X6KUUaRsilzfHbA6xwMM9UX+U0T4/PCqXlbSht/D8qCOetId7Hy3Tv6NJ9fJcEU QsFJ+3WUthIx9rn4r+kkRJ3vb9RFwxGbbsBUnXIg5d7OYNFOeb4fmgdtYsl6uwec3Jku b2gRwdkeyPH2gdK4W2LaPxE/ox8s+SfbiDM2/FNbmu4WXVNq0XfsXyU4ui+8Zls1nLZQ cdBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=FAmjHYXL3rntmC2dTA+uvmdFSuoptao+642a1CSkljo=; b=ukDU/D+hSQFtVtWANhLvv7rfyPHo18Y5Psyqt92lsMycXb5SMuiyLquzeK/HHWVqY8 CPlKcvSnMDnTFSJR77YwQL2XWZP2Q3WZwkwlKscThDyGx2WfimYbF/Vgx3L4ToqDcAS3 wbszqN4LsEjFWhaKLcEwkVFiRj7uOl4h6WLlZeJpvY/GgXxN2ZJOnvqs1iWk2hwOBN+m cKwpZQHcczmh89J6gbtcpB1j9l/33L1cQ5n+TbxhjnVglCp1/d1ZY+DWfSU214Ciu0JH 2ZYoABQj3n97mrTRmX5tIHYaFFV/NwSIjcrTJsyXMPYXqC3NJWAJibfrOP37RNqArYih e0ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=R/D9SHUp; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7-v6si1727499plw.194.2018.02.07.14.57.26; Wed, 07 Feb 2018 14:57:40 -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=@gmail.com header.s=20161025 header.b=R/D9SHUp; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751700AbeBGW4S (ORCPT + 99 others); Wed, 7 Feb 2018 17:56:18 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:38983 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750729AbeBGW4Q (ORCPT ); Wed, 7 Feb 2018 17:56:16 -0500 Received: by mail-lf0-f65.google.com with SMTP id x20so1750172lff.6; Wed, 07 Feb 2018 14:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FAmjHYXL3rntmC2dTA+uvmdFSuoptao+642a1CSkljo=; b=R/D9SHUpB73DZ1CcV8X92qzdxsVr3bg6kyQnN+PA1YaFkwqaayfJwRSmoAcF7eoeZH YA+kWkJU/+6xc8w7RQxHBuJhFu6k57ZCnt5uhrPYJgEzX7YwcNygvyEGwuzzk3SjL7Vg y72jtnbjbYvUm4gIMoiQNJNl/x7+GPMz0SS5GpFA4wIbxPeBqgmz48ZYwcJecKSDUxRq X0RVbz2bT5MrKUDDDQ50ji/FSM3kn+Vz2CswYxuDQYZq+P06HFpJdAgdE4jruAXpc9xX OgpTTUy5IKzspJv9NAeBoTfcNB6Xtpuk0dkvAERCG7uKJgb+P1rP7uhEeXcKPOT+T4HF gfTA== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FAmjHYXL3rntmC2dTA+uvmdFSuoptao+642a1CSkljo=; b=pNHBS40KOMtb9+VgwyDG8HT4UA3EIa+rUucE1U+1spOZyHTvp6GVGxNABla869YCFv LH/h+pPzhochqnNKtTqG7581O/ZOWeLmWVc+R1ZScHVRIFLYhgRsYIDZajbNpJqp525/ VzL/lw9WOcBCiSNquppnmg9bWYx1gO/esExsUdp4mj3DfIfGLnA1ZWXJWyd0C41lgsNr RKxgAkrlOd1SsOW5U+qoh4euVrv3VHQLxdeRzfunZFSPMybhSjIk8svC7rALOR8Tyzrb 2kRvKKfMQNZZLxxET6Dwbz+PTpZy5xMuZ8tRBaIRIY6zkKlU/R0UcIButo2M6Db7/y7f aLSw== X-Gm-Message-State: APf1xPAgJB2Q+3BOgKIweMd1oyuPoFsj/xzm45WyzpqCenmgn0gkz65+ VtDSrw4LEEy6Uq+TTINkCHg= X-Received: by 10.46.5.210 with SMTP id 201mr5373717ljf.34.1518044174381; Wed, 07 Feb 2018 14:56:14 -0800 (PST) Received: from huvuddator (ua-213-113-106-221.cust.bredbandsbolaget.se. [213.113.106.221]) by smtp.gmail.com with ESMTPSA id r68sm502507lja.8.2018.02.07.14.56.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Feb 2018 14:56:13 -0800 (PST) Date: Wed, 7 Feb 2018 23:55:51 +0100 From: Ulf Magnusson To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Sam Ravnborg , Michal Marek , Linus Torvalds , "Luis R. Rodriguez" , linux-kernel@vger.kernel.org, Heinrich Schuchardt Subject: Re: [PATCH 02/14] kconfig: do not write choice values when their dependency becomes n Message-ID: <20180207225551.imdp6gqbdwzyvhwm@huvuddator> References: <1517877294-4826-1-git-send-email-yamada.masahiro@socionext.com> <1517877294-4826-3-git-send-email-yamada.masahiro@socionext.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1517877294-4826-3-git-send-email-yamada.masahiro@socionext.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 06, 2018 at 09:34:42AM +0900, Masahiro Yamada wrote: > "# CONFIG_... is not set" for choice values are wrongly written into > the .config file if they are once visible, then become invisible later. > > Test case > --------- > > ---------------------------(Kconfig)---------------------------- > config A > bool "A" > > choice > prompt "Choice ?" > depends on A > > config CHOICE_B > bool "Choice B" > > config CHOICE_C > bool "Choice C" > > endchoice > ---------------------------------------------------------------- > > ---------------------------(.config)---------------------------- > CONFIG_A=y > ---------------------------------------------------------------- > > With the Kconfig and .config above, > > $ make config > scripts/kconfig/conf --oldaskconfig Kconfig > * > * Linux Kernel Configuration > * > A (A) [Y/n] n > # > # configuration written to .config > # > $ cat .config > # > # Automatically generated file; DO NOT EDIT. > # Linux Kernel Configuration > # > # CONFIG_A is not set > # CONFIG_CHOICE_B is not set > # CONFIG_CHOICE_C is not set > > Here, > > # CONFIG_CHOICE_B is not set > # CONFIG_CHOICE_C is not set > > should not be written into the .config file because their dependency > "depends on A" is unmet. > > Currently, there is no code that clears SYMBOL_WRITE of choice values. > > Clear SYMBOL_WRITE for all symbols in sym_calc_value(), then set it > again after calculating visibility. > > Signed-off-by: Masahiro Yamada > --- > > scripts/kconfig/symbol.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c > index c9123ed..5d6f6b1 100644 > --- a/scripts/kconfig/symbol.c > +++ b/scripts/kconfig/symbol.c > @@ -371,8 +371,7 @@ void sym_calc_value(struct symbol *sym) > sym->curr.tri = no; > return; > } > - if (!sym_is_choice_value(sym)) > - sym->flags &= ~SYMBOL_WRITE; > + sym->flags &= ~SYMBOL_WRITE; > > sym_calc_visibility(sym); > > @@ -385,6 +384,7 @@ void sym_calc_value(struct symbol *sym) > if (sym_is_choice_value(sym) && sym->visible == yes) { > prop = sym_get_choice_prop(sym); > newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no; > + sym->flags |= SYMBOL_WRITE; > } else { > if (sym->visible != no) { > /* if the symbol is visible use the user value > -- > 2.7.4 > Reviewed-by: Ulf Magnusson There's a possible simplification here: All defined symbols, regardless of type, and regardless of whether they're choice value symbols or not, always get written out if they have non-n visibility. Therefore, the sym->visible != no check for SYMBOL_WRITE can be moved to before the symbol type check, which gets rid of two SYMBOL_WRITE assignments and makes it clear that the logic is the same for all paths. This is safe for symbols defined without a type (S_UNKNOWN) too, because conf_write() skips those (plus they already generate a warning). This matches how I do it in the tri_value() function in Kconfiglib: https://github.com/ulfalizer/Kconfiglib/blob/master/kconfiglib.py#L2574. SYMBOL_WRITE corresponds to _write_to_conf. I've included a patch below. I tested it with the Kconfiglib test suite, which verifies that the C implementation still generates the same .config file for all defconfig files as well as for all{no,yes,def}config, for all ARCHes. (The Kconfiglib test suite runs scripts/kconfig/conf and compares its output against it, which means it doubles as a regression test for the C tools.) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c9123ed2b791..13f7fdfe328d 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -371,11 +371,13 @@ void sym_calc_value(struct symbol *sym) sym->curr.tri = no; return; } - if (!sym_is_choice_value(sym)) - sym->flags &= ~SYMBOL_WRITE; + sym->flags &= ~SYMBOL_WRITE; sym_calc_visibility(sym); + if (sym->visible != no) + sym->flags |= SYMBOL_WRITE; + /* set default if recursively called */ sym->curr = newval; @@ -390,7 +392,6 @@ void sym_calc_value(struct symbol *sym) /* if the symbol is visible use the user value * if available, otherwise try the default value */ - sym->flags |= SYMBOL_WRITE; if (sym_has_value(sym)) { newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri, sym->visible); @@ -433,12 +434,9 @@ void sym_calc_value(struct symbol *sym) case S_STRING: case S_HEX: case S_INT: - if (sym->visible != no) { - sym->flags |= SYMBOL_WRITE; - if (sym_has_value(sym)) { - newval.val = sym->def[S_DEF_USER].val; - break; - } + if (sym->visible != no && sym_has_value(sym)) { + newval.val = sym->def[S_DEF_USER].val; + break; } prop = sym_get_default_prop(sym); if (prop) { -- 2.14.1