Skip to content

Commit 7bcf2e0

Browse files
committed
kconfig: add sym_get_choice_menu() helper
Choices and their members are associated via the P_CHOICE property. Currently, prop_get_symbol(sym_get_choice_prop()) is used to obtain the choice of the given choice member. We can do this without relying on P_CHOICE by checking the parent in the menu structure. Introduce a new helper to retrieve the choice if the given symbol is a choice member. This is intended to replace prop_get_symbol(sym_get_choice_prop()) and deprecate P_CHOICE eventually. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 8a22f86 commit 7bcf2e0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

scripts/kconfig/lkc_proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str);
3434
bool sym_set_string_value(struct symbol *sym, const char *newval);
3535
bool sym_is_changeable(struct symbol *sym);
3636
struct property * sym_get_choice_prop(struct symbol *sym);
37+
struct menu *sym_get_choice_menu(struct symbol *sym);
3738
const char * sym_get_string_value(struct symbol *sym);
3839

3940
const char * prop_get_type_name(enum prop_type type);

scripts/kconfig/symbol.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ struct property *sym_get_choice_prop(struct symbol *sym)
7878
return NULL;
7979
}
8080

81+
/**
82+
* sym_get_choice_menu - get the parent choice menu if present
83+
*
84+
* @sym: a symbol pointer
85+
*
86+
* Return: a choice menu if this function is called against a choice member.
87+
*/
88+
struct menu *sym_get_choice_menu(struct symbol *sym)
89+
{
90+
struct menu *menu = NULL;
91+
struct menu *m;
92+
93+
/*
94+
* Choice members must have a prompt. Find a menu entry with a prompt,
95+
* and assume it resides inside a choice block.
96+
*/
97+
list_for_each_entry(m, &sym->menus, link)
98+
if (m->prompt) {
99+
menu = m;
100+
break;
101+
}
102+
103+
if (!menu)
104+
return NULL;
105+
106+
do {
107+
menu = menu->parent;
108+
} while (menu && !menu->sym);
109+
110+
if (menu && menu->sym && sym_is_choice(menu->sym))
111+
return menu;
112+
113+
return NULL;
114+
}
115+
81116
static struct property *sym_get_default_prop(struct symbol *sym)
82117
{
83118
struct property *prop;

0 commit comments

Comments
 (0)