]> www.infradead.org Git - nvme.git/commitdiff
kconfig: introduce choice_set_value() helper
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 11 Jun 2024 17:55:12 +0000 (02:55 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 15 Jul 2024 16:08:36 +0000 (01:08 +0900)
Currently, sym_set_tristate_value() is used to set 'y' to a choice
member, which is confusing because it not only sets 'y' to the given
symbol but also tweaks flags of other symbols as a side effect.

Add a dedicated function for setting the value of the given choice.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/conf.c
scripts/kconfig/lkc_proto.h
scripts/kconfig/mconf.c
scripts/kconfig/nconf.c
scripts/kconfig/symbol.c

index cf8193fc00fcaf44b33b2dc4015cf20e2140b194..5dbdd9459f21285197b330f4368f54324b396db9 100644 (file)
@@ -507,7 +507,7 @@ static void conf_choice(struct menu *menu)
                        print_help(child);
                        continue;
                }
-               sym_set_tristate_value(child->sym, yes);
+               choice_set_value(menu, child->sym);
                return;
        }
 }
index c663fd8b35d263583e26859b4f9c1ac11b33108e..1221709efac17f8f335793c124f54c9ed02681f8 100644 (file)
@@ -28,6 +28,7 @@ bool sym_dep_errors(void);
 enum symbol_type sym_get_type(struct symbol *sym);
 bool sym_tristate_within_range(struct symbol *sym,tristate tri);
 bool sym_set_tristate_value(struct symbol *sym,tristate tri);
+void choice_set_value(struct menu *choice, struct symbol *sym);
 tristate sym_toggle_tristate_value(struct symbol *sym);
 bool sym_string_valid(struct symbol *sym, const char *newval);
 bool sym_string_within_range(struct symbol *sym, const char *str);
index e6227af5165843e5e4f3ab0efe4a0457e469a09c..03709eb734aece0d2f4e97855c1d0672ce46a0d3 100644 (file)
@@ -636,7 +636,7 @@ static void conf_choice(struct menu *menu)
                                if (!child->sym)
                                        break;
 
-                               sym_set_tristate_value(child->sym, yes);
+                               choice_set_value(menu, child->sym);
                        }
                        return;
                case 1:
index addc89ee61d4349a89914913a4a81d6ce85e5982..eb5fc3ccaf9da7e7aaf1fab8ffc6297c1a006aa8 100644 (file)
@@ -1331,7 +1331,7 @@ static void conf_choice(struct menu *menu)
                case ' ':
                case  10:
                case KEY_RIGHT:
-                       sym_set_tristate_value(child->sym, yes);
+                       choice_set_value(menu, child->sym);
                        return;
                case 'h':
                case '?':
index eaff7ac496bd521559f969d95bcdedd191688ac5..8df0a75f40b992fcffd924cbcba359a839feed35 100644 (file)
@@ -516,8 +516,6 @@ bool sym_tristate_within_range(struct symbol *sym, tristate val)
                return false;
        if (sym->visible <= sym->rev_dep.tri)
                return false;
-       if (sym_is_choice_value(sym) && sym->visible == yes)
-               return val == yes;
        return val >= sym->rev_dep.tri && val <= sym->visible;
 }
 
@@ -532,23 +530,6 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
                sym->flags |= SYMBOL_DEF_USER;
                sym_set_changed(sym);
        }
-       /*
-        * setting a choice value also resets the new flag of the choice
-        * symbol and all other choice values.
-        */
-       if (sym_is_choice_value(sym) && val == yes) {
-               struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
-               struct property *prop;
-               struct expr *e;
-
-               cs->def[S_DEF_USER].val = sym;
-               cs->flags |= SYMBOL_DEF_USER;
-               prop = sym_get_choice_prop(cs);
-               for (e = prop->expr; e; e = e->left.expr) {
-                       if (e->right.sym->visible != no)
-                               e->right.sym->flags |= SYMBOL_DEF_USER;
-               }
-       }
 
        sym->def[S_DEF_USER].tri = val;
        if (oldval != val)
@@ -557,10 +538,53 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
        return true;
 }
 
+/**
+ * choice_set_value - set the user input to a choice
+ *
+ * @choice: menu entry for the choice
+ * @sym: selected symbol
+ */
+void choice_set_value(struct menu *choice, struct symbol *sym)
+{
+       struct menu *menu;
+       bool changed = false;
+
+       menu_for_each_sub_entry(menu, choice) {
+               tristate val;
+
+               if (!menu->sym)
+                       continue;
+
+               if (menu->sym->visible == no)
+                       continue;
+
+               val = menu->sym == sym ? yes : no;
+
+               if (menu->sym->curr.tri != val)
+                       changed = true;
+
+               menu->sym->def[S_DEF_USER].tri = val;
+               menu->sym->flags |= SYMBOL_DEF_USER;
+       }
+
+       choice->sym->def[S_DEF_USER].val = sym;
+       choice->sym->flags |= SYMBOL_DEF_USER;
+
+       if (changed)
+               sym_clear_all_valid();
+}
+
 tristate sym_toggle_tristate_value(struct symbol *sym)
 {
+       struct menu *choice;
        tristate oldval, newval;
 
+       choice = sym_get_choice_menu(sym);
+       if (choice) {
+               choice_set_value(choice, sym);
+               return yes;
+       }
+
        oldval = newval = sym_get_tristate_value(sym);
        do {
                switch (newval) {