Skip to content

Commit bd988e7

Browse files
committed
kconfig: introduce choice_set_value() helper
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 <[email protected]>
1 parent dfe8e56 commit bd988e7

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

scripts/kconfig/conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static void conf_choice(struct menu *menu)
507507
print_help(child);
508508
continue;
509509
}
510-
sym_set_tristate_value(child->sym, yes);
510+
choice_set_value(menu, child->sym);
511511
return;
512512
}
513513
}

scripts/kconfig/lkc_proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bool sym_dep_errors(void);
2828
enum symbol_type sym_get_type(struct symbol *sym);
2929
bool sym_tristate_within_range(struct symbol *sym,tristate tri);
3030
bool sym_set_tristate_value(struct symbol *sym,tristate tri);
31+
void choice_set_value(struct menu *choice, struct symbol *sym);
3132
tristate sym_toggle_tristate_value(struct symbol *sym);
3233
bool sym_string_valid(struct symbol *sym, const char *newval);
3334
bool sym_string_within_range(struct symbol *sym, const char *str);

scripts/kconfig/mconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static void conf_choice(struct menu *menu)
636636
if (!child->sym)
637637
break;
638638

639-
sym_set_tristate_value(child->sym, yes);
639+
choice_set_value(menu, child->sym);
640640
}
641641
return;
642642
case 1:

scripts/kconfig/nconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ static void conf_choice(struct menu *menu)
13311331
case ' ':
13321332
case 10:
13331333
case KEY_RIGHT:
1334-
sym_set_tristate_value(child->sym, yes);
1334+
choice_set_value(menu, child->sym);
13351335
return;
13361336
case 'h':
13371337
case '?':

scripts/kconfig/symbol.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ bool sym_tristate_within_range(struct symbol *sym, tristate val)
516516
return false;
517517
if (sym->visible <= sym->rev_dep.tri)
518518
return false;
519-
if (sym_is_choice_value(sym) && sym->visible == yes)
520-
return val == yes;
521519
return val >= sym->rev_dep.tri && val <= sym->visible;
522520
}
523521

@@ -532,23 +530,6 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
532530
sym->flags |= SYMBOL_DEF_USER;
533531
sym_set_changed(sym);
534532
}
535-
/*
536-
* setting a choice value also resets the new flag of the choice
537-
* symbol and all other choice values.
538-
*/
539-
if (sym_is_choice_value(sym) && val == yes) {
540-
struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
541-
struct property *prop;
542-
struct expr *e;
543-
544-
cs->def[S_DEF_USER].val = sym;
545-
cs->flags |= SYMBOL_DEF_USER;
546-
prop = sym_get_choice_prop(cs);
547-
for (e = prop->expr; e; e = e->left.expr) {
548-
if (e->right.sym->visible != no)
549-
e->right.sym->flags |= SYMBOL_DEF_USER;
550-
}
551-
}
552533

553534
sym->def[S_DEF_USER].tri = val;
554535
if (oldval != val)
@@ -557,10 +538,53 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
557538
return true;
558539
}
559540

541+
/**
542+
* choice_set_value - set the user input to a choice
543+
*
544+
* @choice: menu entry for the choice
545+
* @sym: selected symbol
546+
*/
547+
void choice_set_value(struct menu *choice, struct symbol *sym)
548+
{
549+
struct menu *menu;
550+
bool changed = false;
551+
552+
menu_for_each_sub_entry(menu, choice) {
553+
tristate val;
554+
555+
if (!menu->sym)
556+
continue;
557+
558+
if (menu->sym->visible == no)
559+
continue;
560+
561+
val = menu->sym == sym ? yes : no;
562+
563+
if (menu->sym->curr.tri != val)
564+
changed = true;
565+
566+
menu->sym->def[S_DEF_USER].tri = val;
567+
menu->sym->flags |= SYMBOL_DEF_USER;
568+
}
569+
570+
choice->sym->def[S_DEF_USER].val = sym;
571+
choice->sym->flags |= SYMBOL_DEF_USER;
572+
573+
if (changed)
574+
sym_clear_all_valid();
575+
}
576+
560577
tristate sym_toggle_tristate_value(struct symbol *sym)
561578
{
579+
struct menu *choice;
562580
tristate oldval, newval;
563581

582+
choice = sym_get_choice_menu(sym);
583+
if (choice) {
584+
choice_set_value(choice, sym);
585+
return yes;
586+
}
587+
564588
oldval = newval = sym_get_tristate_value(sym);
565589
do {
566590
switch (newval) {

0 commit comments

Comments
 (0)