All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulf Magnusson <ulfalizer@gmail.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-kbuild@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Nicolas Pitre <nicolas.pitre@linaro.org>,
	"Luis R . Rodriguez" <mcgrof@suse.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Sam Ravnborg <sam@ravnborg.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Luis R. Rodriguez" <mcgrof@kernel.org>,
	linux-kernel@vger.kernel.org,
	Heinrich Schuchardt <xypron.glpk@gmx.de>
Subject: Re: [PATCH 02/14] kconfig: do not write choice values when their dependency becomes n
Date: Wed, 7 Feb 2018 23:55:51 +0100	[thread overview]
Message-ID: <20180207225551.imdp6gqbdwzyvhwm@huvuddator> (raw)
In-Reply-To: <1517877294-4826-3-git-send-email-yamada.masahiro@socionext.com>

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 <yamada.masahiro@socionext.com>
> ---
> 
>  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 <ulfalizer@gmail.com>

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

  reply	other threads:[~2018-02-07 22:55 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06  0:34 [PATCH 00/14] Add Kconfig unit tests Masahiro Yamada
2018-02-06  0:34 ` Masahiro Yamada
2018-02-06  0:34 ` [PATCH 01/14] kconfig: send error messages to stderr Masahiro Yamada
2018-02-07 20:24   ` Ulf Magnusson
2018-02-08  1:49     ` Masahiro Yamada
2018-02-08  2:02       ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 02/14] kconfig: do not write choice values when their dependency becomes n Masahiro Yamada
2018-02-07 22:55   ` Ulf Magnusson [this message]
2018-02-08  2:42     ` Masahiro Yamada
2018-02-08  2:46       ` Ulf Magnusson
2018-02-08 21:21         ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 03/14] kconfig: show '?' prompt even if no help text is available Masahiro Yamada
2018-02-07 20:28   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 04/14] kconfig: print additional new line for choice for redirection Masahiro Yamada
2018-02-07 23:34   ` Ulf Magnusson
2018-02-08  6:00     ` Masahiro Yamada
2018-02-06  0:34 ` [PATCH 05/14] kconfig: remove 'config*' pattern from .gitignnore Masahiro Yamada
2018-02-07 23:43   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 06/14] kbuild: define PYTHON2 and PYTHON3 variables instead of PYTHON Masahiro Yamada
2018-02-06  0:34   ` Masahiro Yamada
2018-02-06  9:34   ` Greg Kroah-Hartman
2018-02-06  9:34     ` Greg Kroah-Hartman
2018-02-06 10:44     ` Masahiro Yamada
2018-02-06 10:44       ` Masahiro Yamada
2018-02-06 13:10       ` Greg Kroah-Hartman
2018-02-06 13:10         ` Greg Kroah-Hartman
2018-02-06 17:07         ` Luck, Tony
2018-02-06 17:07           ` Luck, Tony
2018-02-06  0:34 ` [PATCH 07/14] kconfig: test: add framework for Kconfig unit-tests Masahiro Yamada
2018-02-08  0:35   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 08/14] kconfig: test: add basic 'choice' tests Masahiro Yamada
2018-02-07 23:57   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 09/14] kconfig: test: test automatic submenu creation Masahiro Yamada
2018-02-07 23:58   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 10/14] kconfig: test: check if new symbols in choice are asked Masahiro Yamada
2018-02-08  0:09   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 11/14] kconfig: test: check .config sanity for choice values with unmet dep Masahiro Yamada
2018-02-08  0:11   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 12/14] kconfig: test: check visibility of tristate choice values in y choice Masahiro Yamada
2018-02-08  0:13   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 13/14] kconfig: test: check if recursive dependencies are detected Masahiro Yamada
2018-02-08  0:15   ` Ulf Magnusson
2018-02-06  0:34 ` [PATCH 14/14] kconfig: test: check if recursive inclusion is detected Masahiro Yamada
2018-02-08  0:16   ` Ulf Magnusson
2018-02-06  9:38 ` [PATCH 00/14] Add Kconfig unit tests Greg Kroah-Hartman
2018-02-06  9:38   ` Greg Kroah-Hartman
2018-02-07 23:19   ` Ulf Magnusson
2018-02-07 23:19     ` Ulf Magnusson
2018-02-18 19:38 ` Sam Ravnborg
2018-02-18 19:38   ` Sam Ravnborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180207225551.imdp6gqbdwzyvhwm@huvuddator \
    --to=ulfalizer@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mcgrof@suse.com \
    --cc=michal.lkml@markovi.net \
    --cc=nicolas.pitre@linaro.org \
    --cc=rdunlap@infradead.org \
    --cc=sam@ravnborg.org \
    --cc=torvalds@linux-foundation.org \
    --cc=xypron.glpk@gmx.de \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.