kconfig: add sym_get_choice_menu() helper
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 4 May 2024 18:33:28 +0000 (03:33 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Thu, 9 May 2024 19:34:53 +0000 (04:34 +0900)
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 <masahiroy@kernel.org>
scripts/kconfig/lkc_proto.h
scripts/kconfig/symbol.c

index 2807fa584c2b01a37e7fb13bd2c4d570b22798fe..d76aaf4ea11763bda1ef087c43714b24492ae63c 100644 (file)
@@ -34,6 +34,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str);
 bool sym_set_string_value(struct symbol *sym, const char *newval);
 bool sym_is_changeable(struct symbol *sym);
 struct property * sym_get_choice_prop(struct symbol *sym);
+struct menu *sym_get_choice_menu(struct symbol *sym);
 const char * sym_get_string_value(struct symbol *sym);
 
 const char * prop_get_type_name(enum prop_type type);
index 8512c29c84bb896a026d9dfaf016bb73b4284285..23829f44b8f89fe189d52d9d53eb759e2ea6756b 100644 (file)
@@ -78,6 +78,41 @@ struct property *sym_get_choice_prop(struct symbol *sym)
        return NULL;
 }
 
+/**
+ * sym_get_choice_menu - get the parent choice menu if present
+ *
+ * @sym: a symbol pointer
+ *
+ * Return: a choice menu if this function is called against a choice member.
+ */
+struct menu *sym_get_choice_menu(struct symbol *sym)
+{
+       struct menu *menu = NULL;
+       struct menu *m;
+
+       /*
+        * Choice members must have a prompt. Find a menu entry with a prompt,
+        * and assume it resides inside a choice block.
+        */
+       list_for_each_entry(m, &sym->menus, link)
+               if (m->prompt) {
+                       menu = m;
+                       break;
+               }
+
+       if (!menu)
+               return NULL;
+
+       do {
+               menu = menu->parent;
+       } while (menu && !menu->sym);
+
+       if (menu && menu->sym && sym_is_choice(menu->sym))
+               return menu;
+
+       return NULL;
+}
+
 static struct property *sym_get_default_prop(struct symbol *sym)
 {
        struct property *prop;