Commit fde19251 authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

kconfig: remove tristate choice support

I previously submitted a fix for a bug in the choice feature [1], where
I mentioned, "Another (much cleaner) approach would be to remove the
tristate choice support entirely".

There are more issues in the tristate choice feature. For example, you
can observe a couple of bugs in the following test code.

[Test Code]

    config MODULES
            def_bool y
            modules

    choice
            prompt "tristate choice"
            default A

    config A
            tristate "A"

    config B
            tristate "B"

    endchoice

Bug 1: the 'default' property is not correctly processed

'make alldefconfig' produces:

    CONFIG_MODULES=y
    # CONFIG_A is not set
    # CONFIG_B is not set

However, the correct output should be:

    CONFIG_MODULES=y
    CONFIG_A=y
    # CONFIG_B is not set

The unit test file, scripts/kconfig/tests/choice/alldef_expected_config,
is wrong as well.

Bug 2: choice members never get 'y' with randconfig

For the test code above, the following combinations are possible:

               A    B
        (1)    y    n
        (2)    n    y
        (3)    m    m
        (4)    m    n
        (5)    n    m
        (6)    n    n

'make randconfig' never produces (1) or (2).

These bugs are fixable, but a more critical problem is the lack of a
sensible syntax to specify the default for the tristate choice.
The default for the choice must be one of the choice members, which
cannot specify any of the patterns (3) through (6) above.

In addition, I have never seen it being used in a useful way.

The following commits removed unnecessary use of tristate choices:

 - df8df5e4 ("usb: get rid of 'choice' for legacy gadget drivers")
 - bfb57ef0 ("rapidio: remove choice for enumeration")

This commit removes the tristate choice support entirely, which allows
me to delete a lot of code, making further refactoring easier.

Note:
This includes the revert of commit fa64e5f6 ("kconfig/symbol.c:
handle choice_values that depend on 'm' symbols"). It was suspicious
because it did not address the root cause but introduced inconsistency
in visibility between choice members and other symbols.

[1]: https://lore.kernel.org/linux-kbuild/20240427104231.2728905-1-masahiroy@kernel.org/T/#m0a1bb6992581462ceca861b409bb33cb8fd7dbae



Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
parent 03638aaa
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -409,16 +409,9 @@ choices::
	"endchoice"

This defines a choice group and accepts any of the above attributes as
options. A choice can only be of type bool or tristate.  If no type is
specified for a choice, its type will be determined by the type of
the first choice element in the group or remain unknown if none of the
choice elements have a type specified, as well.

While a boolean choice only allows a single config entry to be
selected, a tristate choice also allows any number of config entries
to be set to 'm'. This can be used if multiple drivers for a single
hardware exists and only a single driver can be compiled/loaded into
the kernel, but all drivers can be compiled as modules.
options.

A choice only allows a single config entry to be selected.

comment::

+6 −50
Original line number Diff line number Diff line
@@ -114,21 +114,13 @@ static void set_randconfig_seed(void)
	srand(seed);
}

static bool randomize_choice_values(struct symbol *csym)
static void randomize_choice_values(struct symbol *csym)
{
	struct property *prop;
	struct symbol *sym;
	struct expr *e;
	int cnt, def;

	/*
	 * If choice is mod then we may have more items selected
	 * and if no then no-one.
	 * In both cases stop.
	 */
	if (csym->curr.tri != yes)
		return false;

	prop = sym_get_choice_prop(csym);

	/* count entries in choice block */
@@ -157,8 +149,6 @@ static bool randomize_choice_values(struct symbol *csym)
	csym->flags |= SYMBOL_DEF_USER;
	/* clear VALID to get value calculated */
	csym->flags &= ~SYMBOL_VALID;

	return true;
}

enum conf_def_mode {
@@ -269,15 +259,6 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)

	sym_clear_all_valid();

	/*
	 * We have different type of choice blocks.
	 * If curr.tri equals to mod then we can select several
	 * choice symbols in one block.
	 * In this case we do nothing.
	 * If curr.tri equals yes then only one symbol can be
	 * selected in a choice block and we set it to yes,
	 * and the rest to no.
	 */
	if (mode != def_random) {
		for_all_symbols(csym) {
			if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
@@ -292,12 +273,11 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)

		sym_calc_value(csym);
		if (mode == def_random)
			has_changed |= randomize_choice_values(csym);
		else {
			randomize_choice_values(csym);
		else
			set_all_choice_values(csym);
		has_changed = true;
	}
	}

	return has_changed;
}
@@ -454,27 +434,6 @@ static void conf_choice(struct menu *menu)

	sym = menu->sym;
	is_new = !sym_has_value(sym);
	if (sym_is_changeable(sym)) {
		conf_sym(menu);
		sym_calc_value(sym);
		switch (sym_get_tristate_value(sym)) {
		case no:
		case mod:
			return;
		case yes:
			break;
		}
	} else {
		switch (sym_get_tristate_value(sym)) {
		case no:
			return;
		case mod:
			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
			return;
		case yes:
			break;
		}
	}

	while (1) {
		int cnt, def;
@@ -596,9 +555,7 @@ static void conf(struct menu *menu)

	if (sym_is_choice(sym)) {
		conf_choice(menu);
		if (sym->curr.tri != mod)
		return;
		goto conf_childs;
	}

	switch (sym->type) {
@@ -631,8 +588,7 @@ static void check_conf(struct menu *menu)

	sym = menu->sym;
	if (sym && !sym_has_value(sym) &&
	    (sym_is_changeable(sym) ||
	     (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes))) {
	    (sym_is_changeable(sym) || sym_is_choice(sym))) {

		switch (input_mode) {
		case listnewconfig:
+3 −14
Original line number Diff line number Diff line
@@ -462,22 +462,12 @@ int conf_read_simple(const char *name, int def)

		if (sym && sym_is_choice_value(sym)) {
			struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
			switch (sym->def[def].tri) {
			case no:
				break;
			case mod:
				if (cs->def[def].tri == yes) {
					conf_warning("%s creates inconsistent choice state", sym->name);
					cs->flags &= ~def_flags;
				}
				break;
			case yes:
			if (sym->def[def].tri == yes) {
				if (cs->def[def].tri != no)
					conf_warning("override: %s changes choice state", sym->name);
				cs->def[def].val = sym;
				break;
				cs->def[def].tri = yes;
			}
			cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
		}
	}
	free(line);
@@ -806,8 +796,7 @@ int conf_write_defconfig(const char *filename)

				ds = sym_choice_default(choice->sym);
				if (sym == ds) {
					if ((sym->type == S_BOOLEAN) &&
					    sym_get_tristate_value(sym) == yes)
					if (sym_get_tristate_value(sym) == yes)
						continue;
				}
			}
+2 −4
Original line number Diff line number Diff line
@@ -1067,11 +1067,9 @@ static gchar **fill_row(struct menu *menu)
			row[COL_VALUE] =
			    g_strdup(menu_get_prompt(def_menu));

		if (sym_get_type(sym) == S_BOOLEAN) {
		row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
		return row;
	}
	}
	if (sym->flags & SYMBOL_CHOICEVAL)
		row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);

+7 −21
Original line number Diff line number Diff line
@@ -523,28 +523,14 @@ static void build_conf(struct menu *menu)
				def_menu = child;
		}

		val = sym_get_tristate_value(sym);
		if (sym_is_changeable(sym)) {
			switch (val) {
			case yes: ch = '*'; break;
			case mod: ch = 'M'; break;
			default:  ch = ' '; break;
			}
			item_make("<%c>", ch);
			item_set_tag('t');
			item_set_data(menu);
		} else {
		item_make("   ");
		item_set_tag(def_menu ? 't' : ':');
		item_set_data(menu);
		}

		item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
		if (val == yes) {
		if (def_menu)
			item_add_str(" (%s)  --->", menu_get_prompt(def_menu));
		return;
		}
	} else {
		if (menu == current_menu) {
			item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
@@ -814,7 +800,7 @@ static void conf(struct menu *menu, struct menu *active_menu)
					conf(submenu, NULL);
				break;
			case 't':
				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
				if (sym_is_choice(sym))
					conf_choice(submenu);
				else if (submenu->prompt->type == P_MENU)
					conf(submenu, NULL);
Loading