kconfig: link menus to a symbol
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 3 Mar 2024 04:00:33 +0000 (13:00 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 9 Mar 2024 06:01:00 +0000 (15:01 +0900)
Currently, there is no direct link from (struct symbol) to (struct menu).

It is still possible to access associated menus through the P_SYMBOL
property, because property::menu is the relevant menu entry, but it
results in complex code, as seen in get_symbol_str().

Use a linked list for simpler traversal of relevant menus.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
scripts/kconfig/expr.h
scripts/kconfig/menu.c
scripts/kconfig/symbol.c

index 3bc375f..0158f5e 100644 (file)
@@ -108,6 +108,9 @@ struct symbol {
         */
        tristate visible;
 
+       /* config entries associated with this symbol */
+       struct list_head menus;
+
        /* SYMBOL_* flags */
        int flags;
 
@@ -222,6 +225,8 @@ struct menu {
         */
        struct symbol *sym;
 
+       struct list_head link;  /* link to symbol::menus */
+
        /*
         * The prompt associated with the node. This holds the prompt for a
         * symbol as well as the text for a menu or comment, along with the
index 4446594..571394e 100644 (file)
@@ -57,8 +57,10 @@ void menu_add_entry(struct symbol *sym)
        *last_entry_ptr = menu;
        last_entry_ptr = &menu->next;
        current_entry = menu;
-       if (sym)
+       if (sym) {
                menu_add_symbol(P_SYMBOL, sym, NULL);
+               list_add_tail(&menu->link, &sym->menus);
+       }
 }
 
 struct menu *menu_add_menu(void)
index dd5cf97..81fe188 100644 (file)
 struct symbol symbol_yes = {
        .name = "y",
        .curr = { "y", yes },
+       .menus = LIST_HEAD_INIT(symbol_yes.menus),
        .flags = SYMBOL_CONST|SYMBOL_VALID,
 };
 
 struct symbol symbol_mod = {
        .name = "m",
        .curr = { "m", mod },
+       .menus = LIST_HEAD_INIT(symbol_mod.menus),
        .flags = SYMBOL_CONST|SYMBOL_VALID,
 };
 
 struct symbol symbol_no = {
        .name = "n",
        .curr = { "n", no },
+       .menus = LIST_HEAD_INIT(symbol_no.menus),
        .flags = SYMBOL_CONST|SYMBOL_VALID,
 };
 
@@ -838,6 +841,7 @@ struct symbol *sym_lookup(const char *name, int flags)
        symbol->name = new_name;
        symbol->type = S_UNKNOWN;
        symbol->flags = flags;
+       INIT_LIST_HEAD(&symbol->menus);
 
        hash_add(sym_hashtable, &symbol->node, hash);