kconfig: do not reparent the menu inside a choice block
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 23 Mar 2024 08:51:01 +0000 (17:51 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Thu, 28 Mar 2024 02:02:13 +0000 (11:02 +0900)
The boolean 'choice' is used to list exclusively selected config
options.

You must not add a dependency between choice members, because such a
dependency would create an invisible entry.

In the following test case, it is impossible to choose 'C'.

[Test Case 1]

  choice
          prompt "Choose one, but how to choose C?"

  config A
          bool "A"

  config B
          bool "B"

  config C
          bool "C"
          depends on A

  endchoice

Hence, Kconfig shows the following error message:

  Kconfig:1:error: recursive dependency detected!
  Kconfig:1:      choice <choice> contains symbol C
  Kconfig:10:     symbol C is part of choice A
  Kconfig:4:      symbol A is part of choice <choice>
  For a resolution refer to Documentation/kbuild/kconfig-language.rst
  subsection "Kconfig recursive dependency limitations"

However, Kconfig does not report anything for the following similar code:

[Test Case 2]

  choice
         prompt "Choose one, but how to choose B?"

  config A
          bool "A"

  config B
          bool "B"
          depends on A

  config C
          bool "C"

  endchoice

This is because menu_finalize() reparents the menu tree when an entry
depends on the preceding one.

With reparenting, the menu tree:

  choice
   |- A
   |- B
   \- C

... will be transformed into the following structure:

  choice
   |- A
   |  \- B
   \- C

Consequently, Kconfig considers only 'A' and 'C' as choice members.
This behavior is awkward. The second test case should be an error too.

This commit stops reparenting inside a choice.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/conf.c
scripts/kconfig/lkc.h
scripts/kconfig/menu.c
scripts/kconfig/parser.y

index b5730061872baea05947ca95ec94391a0a468e36..965bb40c50e5170a1341d662e5be7607a866e928 100644 (file)
@@ -552,11 +552,6 @@ static int conf_choice(struct menu *menu)
                        continue;
                }
                sym_set_tristate_value(child->sym, yes);
-               for (child = child->list; child; child = child->next) {
-                       indent += 2;
-                       conf(child);
-                       indent -= 2;
-               }
                return 1;
        }
 }
index e69d7c59d930272e177618e440c42bee1e8bbce6..e7cc9e985c4f0679db316f09d0afb001cc07de7c 100644 (file)
@@ -89,7 +89,7 @@ void menu_add_visibility(struct expr *dep);
 struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
 void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
 void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
-void menu_finalize(struct menu *parent);
+void menu_finalize(void);
 void menu_set_type(int type);
 
 extern struct menu rootmenu;
index 8498481e6afe36786b969efb6551528c1156ea05..3b822cd110f478376e7ee4fe518f368023863f3d 100644 (file)
@@ -282,7 +282,7 @@ static void sym_check_prop(struct symbol *sym)
        }
 }
 
-void menu_finalize(struct menu *parent)
+static void _menu_finalize(struct menu *parent, bool inside_choice)
 {
        struct menu *menu, *last_menu;
        struct symbol *sym;
@@ -296,7 +296,12 @@ void menu_finalize(struct menu *parent)
                 * and propagate parent dependencies before moving on.
                 */
 
-               if (sym && sym_is_choice(sym)) {
+               bool is_choice = false;
+
+               if (sym && sym_is_choice(sym))
+                       is_choice = true;
+
+               if (is_choice) {
                        if (sym->type == S_UNKNOWN) {
                                /* find the first choice value to find out choice type */
                                current_entry = parent;
@@ -394,7 +399,7 @@ void menu_finalize(struct menu *parent)
                        }
                }
 
-               if (sym && sym_is_choice(sym))
+               if (is_choice)
                        expr_free(parentdep);
 
                /*
@@ -402,8 +407,8 @@ void menu_finalize(struct menu *parent)
                 * moving on
                 */
                for (menu = parent->list; menu; menu = menu->next)
-                       menu_finalize(menu);
-       } else if (sym) {
+                       _menu_finalize(menu, is_choice);
+       } else if (!inside_choice && sym) {
                /*
                 * Automatic submenu creation. If sym is a symbol and A, B, C,
                 * ... are consecutive items (symbols, menus, ifs, etc.) that
@@ -463,7 +468,7 @@ void menu_finalize(struct menu *parent)
                        /* Superset, put in submenu */
                        expr_free(dep2);
                next:
-                       menu_finalize(menu);
+                       _menu_finalize(menu, false);
                        menu->parent = parent;
                        last_menu = menu;
                }
@@ -582,6 +587,11 @@ void menu_finalize(struct menu *parent)
        }
 }
 
+void menu_finalize(void)
+{
+       _menu_finalize(&rootmenu, false);
+}
+
 bool menu_has_prompt(struct menu *menu)
 {
        if (!menu->prompt)
index b45bfaf0a02b1234f49dd328a350a1de8f2641df..7fb996612c966075883d945f4a8174653f025d66 100644 (file)
@@ -515,7 +515,7 @@ void conf_parse(const char *name)
                menu_add_prompt(P_MENU, "Main menu", NULL);
        }
 
-       menu_finalize(&rootmenu);
+       menu_finalize();
 
        menu = &rootmenu;
        while (menu) {