linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file
@ 2024-05-04 18:33 Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 02/10] kconfig: gconf: remove debug code Masahiro Yamada
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

Every time a config file is loaded (either by clicking the "Load" button
or selecting "File" -> "Load" from the menu), a new tree structure is
appended to the widget.

The current tree needs to be cleared by calling gtk_tree_store_clear().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/gconf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 67a27c497c40..12b55f2e369b 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -487,7 +487,7 @@ load_filename(GtkFileSelection * file_selector, gpointer user_data)
 	if (conf_read(fn))
 		text_insert_msg("Error", "Unable to load configuration !");
 	else
-		display_tree(&rootmenu);
+		display_tree_part();
 }
 
 void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
@@ -1399,6 +1399,8 @@ static void display_tree_part(void)
 		display_tree(current);
 	else if (view_mode == SPLIT_VIEW)
 		display_tree(browsed);
+	else if (view_mode == FULL_VIEW)
+		display_tree(&rootmenu);
 	gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
 }
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] kconfig: gconf: remove debug code
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 03/10] kconfig: gconf: use MENU_CHANGED instead of SYMBOL_CHANGED Masahiro Yamada
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

This is not so useful. If necessary, you can insert printf() or
whatever during debugging.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/gconf.c | 49 +----------------------------------------
 1 file changed, 1 insertion(+), 48 deletions(-)

diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 12b55f2e369b..89614f1e49e6 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -18,8 +18,6 @@
 #include <unistd.h>
 #include <time.h>
 
-//#define DEBUG
-
 enum {
 	SINGLE_VIEW, SPLIT_VIEW, FULL_VIEW
 };
@@ -71,33 +69,6 @@ static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row);
 static gchar **fill_row(struct menu *menu);
 static void conf_changed(void);
 
-/* Helping/Debugging Functions */
-#ifdef DEBUG
-static const char *dbg_sym_flags(int val)
-{
-	static char buf[256];
-
-	bzero(buf, 256);
-
-	if (val & SYMBOL_CONST)
-		strcat(buf, "const/");
-	if (val & SYMBOL_CHECK)
-		strcat(buf, "check/");
-	if (val & SYMBOL_CHOICEVAL)
-		strcat(buf, "choiceval/");
-	if (val & SYMBOL_VALID)
-		strcat(buf, "valid/");
-	if (val & SYMBOL_WRITE)
-		strcat(buf, "write/");
-	if (val & SYMBOL_CHANGED)
-		strcat(buf, "changed/");
-
-	buf[strlen(buf) - 1] = '\0';
-
-	return buf;
-}
-#endif
-
 static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
 				GtkStyle *style, gchar *btn_name, gchar **xpm)
 {
@@ -1262,12 +1233,6 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
 		else
 			menu2 = NULL;	// force adding of a first child
 
-#ifdef DEBUG
-		printf("%*c%s | %s\n", indent, ' ',
-		       menu1 ? menu_get_prompt(menu1) : "nil",
-		       menu2 ? menu_get_prompt(menu2) : "nil");
-#endif
-
 		if ((opt_mode == OPT_NORMAL && !menu_is_visible(child1)) ||
 		    (opt_mode == OPT_PROMPT && !menu_has_prompt(child1)) ||
 		    (opt_mode == OPT_ALL    && !menu_get_prompt(child1))) {
@@ -1354,19 +1319,7 @@ static void display_tree(struct menu *menu)
 		    (opt_mode == OPT_PROMPT && menu_has_prompt(child)) ||
 		    (opt_mode == OPT_ALL    && menu_get_prompt(child)))
 			place_node(child, fill_row(child));
-#ifdef DEBUG
-		printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
-		printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : "");
-		printf("%s", prop_get_type_name(ptype));
-		printf(" | ");
-		if (sym) {
-			printf("%s", sym_type_name(sym->type));
-			printf(" | ");
-			printf("%s", dbg_sym_flags(sym->flags));
-			printf("\n");
-		} else
-			printf("\n");
-#endif
+
 		if ((view_mode != FULL_VIEW) && (ptype == P_MENU)
 		    && (tree == tree2))
 			continue;
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] kconfig: gconf: use MENU_CHANGED instead of SYMBOL_CHANGED
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 02/10] kconfig: gconf: remove debug code Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 04/10] kconfig: used linked list in sym_set_changed() Masahiro Yamada
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

SYMBOL_CHANGED and MENU_CHANGED are used to update GUI frontends
when the symbol value is changed. These are used inconsistently:
SYMBOL_CHANGED in gconf.c and MENU_CHANGE in qconf.cc.

MENU_CHANGED works more properly when a symbol has multiple prompts
(although such code is not ideal).

[test code]

    config FOO
            bool "foo prompt 1"

    config FOO
            bool "foo prompt 2"

In gconfig, if one of the two checkboxes is clicked, only the first
one is toggled. In xconfig, the two checkboxes work in sync.

Replace SYMBOL_CHANGED in gconf.c with MENU_CHANGED to align with
the xconfig behavior.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/gconf.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 89614f1e49e6..10d602faa51e 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -1047,7 +1047,7 @@ static gchar **fill_row(struct menu *menu)
 	row[COL_NAME] = g_strdup(sym->name);
 
 	sym_calc_value(sym);
-	sym->flags &= ~SYMBOL_CHANGED;
+	menu->flags &= ~MENU_CHANGED;
 
 	if (sym_is_choice(sym)) {	// parse childs for getting final value
 		struct menu *child;
@@ -1273,7 +1273,7 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
 				else
 					goto reparse;	// next child
 			}
-		} else if (sym && (sym->flags & SYMBOL_CHANGED)) {
+		} else if (sym && (child1->flags & MENU_CHANGED)) {
 			set_node(child2, menu1, fill_row(menu1));
 		}
 
@@ -1289,7 +1289,6 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
 /* Display the whole tree (single/split/full view) */
 static void display_tree(struct menu *menu)
 {
-	struct symbol *sym;
 	struct property *prop;
 	struct menu *child;
 	enum prop_type ptype;
@@ -1301,11 +1300,9 @@ static void display_tree(struct menu *menu)
 
 	for (child = menu->list; child; child = child->next) {
 		prop = child->prompt;
-		sym = child->sym;
 		ptype = prop ? prop->type : P_UNKNOWN;
 
-		if (sym)
-			sym->flags &= ~SYMBOL_CHANGED;
+		menu->flags &= ~MENU_CHANGED;
 
 		if ((view_mode == SPLIT_VIEW)
 		    && !(child->flags & MENU_ROOT) && (tree == tree1))
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] kconfig: used linked list in sym_set_changed()
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 02/10] kconfig: gconf: remove debug code Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 03/10] kconfig: gconf: use MENU_CHANGED instead of SYMBOL_CHANGED Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 05/10] kconfig: add sym_get_choice_menu() helper Masahiro Yamada
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

Following the approach employed in commit bedf92362317 ("kconfig: use
linked list in get_symbol_str() to iterate over menus"), simplify the
iteration on the menus of the specified symbol.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/symbol.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index b909c64f3bac..8512c29c84bb 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -152,13 +152,11 @@ static void sym_validate_range(struct symbol *sym)
 
 static void sym_set_changed(struct symbol *sym)
 {
-	struct property *prop;
+	struct menu *menu;
 
 	sym->flags |= SYMBOL_CHANGED;
-	for (prop = sym->prop; prop; prop = prop->next) {
-		if (prop->menu)
-			prop->menu->flags |= MENU_CHANGED;
-	}
+	list_for_each_entry(menu, &sym->menus, link)
+		menu->flags |= MENU_CHANGED;
 }
 
 static void sym_set_all_changed(void)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] kconfig: add sym_get_choice_menu() helper
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (2 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 04/10] kconfig: used linked list in sym_set_changed() Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 06/10] kconfig: use sym_get_choice_menu() in conf_write_defconfig() Masahiro Yamada
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

Choices and their members are associated via the P_CHOICE property.

Currently, prop_get_symbol(sym_get_choice_prop(sym)) 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(sym))
and deprecate P_CHOICE eventually.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/lkc_proto.h |  1 +
 scripts/kconfig/symbol.c    | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 2807fa584c2b..d76aaf4ea117 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -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);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 8512c29c84bb..23829f44b8f8 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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;
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] kconfig: use sym_get_choice_menu() in conf_write_defconfig()
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (3 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 05/10] kconfig: add sym_get_choice_menu() helper Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 07/10] kconfig: use menu_list_for_each_sym() in sym_check_choice_deps() Masahiro Yamada
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

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.

Replace it with sym_get_choice_menu(), which retrieves the choice
without relying on P_CHOICE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/confdata.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 5caec434e6f4..e68890bbc035 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -794,6 +794,8 @@ int conf_write_defconfig(const char *filename)
 	sym_clear_all_valid();
 
 	menu_for_each_entry(menu) {
+		struct menu *choice_menu;
+
 		sym = menu->sym;
 		if (sym && !sym_is_choice(sym)) {
 			sym_calc_value(sym);
@@ -811,12 +813,11 @@ int conf_write_defconfig(const char *filename)
 			 * If symbol is a choice value and equals to the
 			 * default for a choice - skip.
 			 */
-			if (sym_is_choice_value(sym)) {
-				struct symbol *cs;
+			choice_menu = sym_get_choice_menu(sym);
+			if (choice_menu) {
 				struct symbol *ds;
 
-				cs = prop_get_symbol(sym_get_choice_prop(sym));
-				ds = sym_choice_default(cs);
+				ds = sym_choice_default(choice_menu->sym);
 				if (sym == ds) {
 					if ((sym->type == S_BOOLEAN) &&
 					    sym_get_tristate_value(sym) == yes)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] kconfig: use menu_list_for_each_sym() in sym_check_choice_deps()
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (4 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 06/10] kconfig: use sym_get_choice_menu() in conf_write_defconfig() Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 08/10] kconfig: turn conf_choice() into void function Masahiro Yamada
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

Choices and their members are associated via the P_CHOICE property.

Currently, sym_get_choice_prop() and expr_list_for_each_sym() are
used to iterate on choice members.

Replace them with menu_for_each_sub_entry(), which achieves the same
without relying on P_CHOICE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/symbol.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 23829f44b8f8..75e7506fcb5c 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -1204,16 +1204,18 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 
 static struct symbol *sym_check_choice_deps(struct symbol *choice)
 {
-	struct symbol *sym, *sym2;
-	struct property *prop;
-	struct expr *e;
+	struct menu *menu, *child;
+	struct symbol *sym2;
 	struct dep_stack stack;
 
 	dep_stack_insert(&stack, choice);
 
-	prop = sym_get_choice_prop(choice);
-	expr_list_for_each_sym(prop->expr, e, sym)
-		sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
+	menu = list_first_entry(&choice->menus, struct menu, link);
+
+	menu_for_each_sub_entry(child, menu) {
+		if (child->sym)
+			child->sym->flags |= SYMBOL_CHECK | SYMBOL_CHECKED;
+	}
 
 	choice->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
 	sym2 = sym_check_sym_deps(choice);
@@ -1221,14 +1223,17 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
 	if (sym2)
 		goto out;
 
-	expr_list_for_each_sym(prop->expr, e, sym) {
-		sym2 = sym_check_sym_deps(sym);
+	menu_for_each_sub_entry(child, menu) {
+		if (!child->sym)
+			continue;
+		sym2 = sym_check_sym_deps(child->sym);
 		if (sym2)
 			break;
 	}
 out:
-	expr_list_for_each_sym(prop->expr, e, sym)
-		sym->flags &= ~SYMBOL_CHECK;
+	menu_for_each_sub_entry(child, menu)
+		if (child->sym)
+			child->sym->flags &= ~SYMBOL_CHECK;
 
 	if (sym2 && sym_is_choice_value(sym2) &&
 	    prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] kconfig: turn conf_choice() into void function
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (5 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 07/10] kconfig: use menu_list_for_each_sym() in sym_check_choice_deps() Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 09/10] kconfig: turn missing prompt for choice members into error Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 10/10] kconfig: turn defaults and additional " Masahiro Yamada
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

The return value of conf_choice() is not used.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/conf.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 0156ca13f949..8ad2c52d9b1f 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -446,7 +446,7 @@ static int conf_sym(struct menu *menu)
 	}
 }
 
-static int conf_choice(struct menu *menu)
+static void conf_choice(struct menu *menu)
 {
 	struct symbol *sym, *def_sym;
 	struct menu *child;
@@ -459,19 +459,18 @@ static int conf_choice(struct menu *menu)
 		sym_calc_value(sym);
 		switch (sym_get_tristate_value(sym)) {
 		case no:
-			return 1;
 		case mod:
-			return 0;
+			return;
 		case yes:
 			break;
 		}
 	} else {
 		switch (sym_get_tristate_value(sym)) {
 		case no:
-			return 1;
+			return;
 		case mod:
 			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
-			return 0;
+			return;
 		case yes:
 			break;
 		}
@@ -551,7 +550,7 @@ static int conf_choice(struct menu *menu)
 			continue;
 		}
 		sym_set_tristate_value(child->sym, yes);
-		return 1;
+		return;
 	}
 }
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] kconfig: turn missing prompt for choice members into error
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (6 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 08/10] kconfig: turn conf_choice() into void function Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-04 18:33 ` [PATCH 10/10] kconfig: turn defaults and additional " Masahiro Yamada
  8 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

Choice members must have a prompt; hence make it an error.

While I was here, I moved the check to the parser to slim down
_menu_finalize().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/menu.c   |  2 --
 scripts/kconfig/parser.y | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index e01b9ee87c05..a9b1e451dfe7 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -507,8 +507,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
 		    menu->sym && !sym_is_choice_value(menu->sym)) {
 			current_entry = menu;
 			menu->sym->flags |= SYMBOL_CHOICEVAL;
-			if (!menu->prompt)
-				menu_warn(menu, "choice value must have a prompt");
 			for (prop = menu->sym->prop; prop; prop = prop->next) {
 				if (prop->type == P_DEFAULT)
 					prop_warn(prop, "defaults for choice "
diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index 613fa8c9c2d0..ed86869e5ed0 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -30,6 +30,8 @@ static bool zconf_endtoken(const char *tokenname,
 
 struct menu *current_menu, *current_entry;
 
+static bool inside_choice = false;
+
 %}
 
 %union
@@ -145,6 +147,14 @@ config_entry_start: T_CONFIG nonconst_symbol T_EOL
 
 config_stmt: config_entry_start config_option_list
 {
+	if (inside_choice) {
+		if (!current_entry->prompt) {
+			fprintf(stderr, "%s:%d: error: choice member must have a prompt\n",
+				current_entry->filename, current_entry->lineno);
+			yynerrs++;
+		}
+	}
+
 	printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno);
 };
 
@@ -237,10 +247,14 @@ choice_entry: choice choice_option_list
 	}
 
 	$$ = menu_add_menu();
+
+	inside_choice = true;
 };
 
 choice_end: end
 {
+	inside_choice = false;
+
 	if (zconf_endtoken($1, "choice")) {
 		menu_end_menu();
 		printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] kconfig: turn defaults and additional prompt for choice members into error
  2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
                   ` (7 preceding siblings ...)
  2024-05-04 18:33 ` [PATCH 09/10] kconfig: turn missing prompt for choice members into error Masahiro Yamada
@ 2024-05-04 18:33 ` Masahiro Yamada
  2024-05-05 15:01   ` Masahiro Yamada
  8 siblings, 1 reply; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-04 18:33 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada

menu_finalize() warns default properties for choice members and prompts
outside the choice block. These should be hard errors.

While I was here, I moved the checks to slim down menu_finalize().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/menu.c   | 10 ----------
 scripts/kconfig/parser.y | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index a9b1e451dfe7..bee96c9964fd 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -507,16 +507,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
 		    menu->sym && !sym_is_choice_value(menu->sym)) {
 			current_entry = menu;
 			menu->sym->flags |= SYMBOL_CHOICEVAL;
-			for (prop = menu->sym->prop; prop; prop = prop->next) {
-				if (prop->type == P_DEFAULT)
-					prop_warn(prop, "defaults for choice "
-						  "values not supported");
-				if (prop->menu == menu)
-					continue;
-				if (prop->type == P_PROMPT &&
-				    prop->menu->parent->sym != sym)
-					prop_warn(prop, "choice value used outside its choice group");
-			}
 			/* Non-tristate choice values of tristate choices must
 			 * depend on the choice being set to Y. The choice
 			 * values' dependencies were propagated to their
diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index ed86869e5ed0..0a9e249b5dcc 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -476,6 +476,37 @@ assign_val:
 
 %%
 
+/**
+ * choice_check_sanity - check sanity of a choice member
+ *
+ * @menu: menu of the choice member
+ *
+ * Return: -1 if an error is found, 0 otherwise.
+ */
+static int choice_check_sanity(struct menu *menu)
+{
+	struct property *prop;
+	int ret = 0;
+
+	for (prop = menu->sym->prop; prop; prop = prop->next) {
+		if (prop->type == P_DEFAULT) {
+			fprintf(stderr, "%s:%d: error: %s",
+				prop->filename, prop->lineno,
+				"defaults for choice values not supported\n");
+			ret = -1;
+		}
+
+		if (prop->menu != menu && prop->type == P_PROMPT) {
+			fprintf(stderr, "%s:%d: error: %s",
+				prop->filename, prop->lineno,
+				"choice value has a prompt outside its choice group\n");
+			ret = -1;
+		}
+	}
+
+	return ret;
+}
+
 void conf_parse(const char *name)
 {
 	struct menu *menu;
@@ -523,8 +554,16 @@ void conf_parse(const char *name)
 	menu_finalize();
 
 	menu_for_each_entry(menu) {
+		struct menu *child;
+
 		if (menu->sym && sym_check_deps(menu->sym))
 			yynerrs++;
+
+		if (menu->sym && sym_is_choice(menu->sym)) {
+			menu_for_each_sub_entry(child, menu)
+				if (child->sym && choice_check_sanity(child))
+					yynerrs++;
+		}
 	}
 
 	if (yynerrs)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 10/10] kconfig: turn defaults and additional prompt for choice members into error
  2024-05-04 18:33 ` [PATCH 10/10] kconfig: turn defaults and additional " Masahiro Yamada
@ 2024-05-05 15:01   ` Masahiro Yamada
  0 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2024-05-05 15:01 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel

On Sun, May 5, 2024 at 3:34 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> menu_finalize() warns default properties for choice members and prompts
> outside the choice block. These should be hard errors.
>
> While I was here, I moved the checks to slim down menu_finalize().
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
>  scripts/kconfig/menu.c   | 10 ----------
>  scripts/kconfig/parser.y | 39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 10 deletions(-)
>
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index a9b1e451dfe7..bee96c9964fd 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -507,16 +507,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
>                     menu->sym && !sym_is_choice_value(menu->sym)) {
>                         current_entry = menu;
>                         menu->sym->flags |= SYMBOL_CHOICEVAL;
> -                       for (prop = menu->sym->prop; prop; prop = prop->next) {
> -                               if (prop->type == P_DEFAULT)
> -                                       prop_warn(prop, "defaults for choice "
> -                                                 "values not supported");
> -                               if (prop->menu == menu)
> -                                       continue;
> -                               if (prop->type == P_PROMPT &&
> -                                   prop->menu->parent->sym != sym)
> -                                       prop_warn(prop, "choice value used outside its choice group");
> -                       }
>                         /* Non-tristate choice values of tristate choices must
>                          * depend on the choice being set to Y. The choice
>                          * values' dependencies were propagated to their
> diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
> index ed86869e5ed0..0a9e249b5dcc 100644
> --- a/scripts/kconfig/parser.y
> +++ b/scripts/kconfig/parser.y
> @@ -476,6 +476,37 @@ assign_val:
>
>  %%
>
> +/**
> + * choice_check_sanity - check sanity of a choice member
> + *
> + * @menu: menu of the choice member
> + *
> + * Return: -1 if an error is found, 0 otherwise.
> + */
> +static int choice_check_sanity(struct menu *menu)
> +{
> +       struct property *prop;
> +       int ret = 0;
> +
> +       for (prop = menu->sym->prop; prop; prop = prop->next) {
> +               if (prop->type == P_DEFAULT) {
> +                       fprintf(stderr, "%s:%d: error: %s",
> +                               prop->filename, prop->lineno,
> +                               "defaults for choice values not supported\n");
> +                       ret = -1;
> +               }
> +
> +               if (prop->menu != menu && prop->type == P_PROMPT) {
> +                       fprintf(stderr, "%s:%d: error: %s",
> +                               prop->filename, prop->lineno,
> +                               "choice value has a prompt outside its choice group\n");
> +                       ret = -1;
> +               }
> +       }
> +
> +       return ret;
> +}
> +



I observed an error in powerpc.

I will fix up this as follows:


diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index 0a9e249b5dcc..ff709001b1f0 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -496,7 +496,8 @@ static int choice_check_sanity(struct menu *menu)
                        ret = -1;
                }

-               if (prop->menu != menu && prop->type == P_PROMPT) {
+               if (prop->menu != menu && prop->type == P_PROMPT &&
+                   prop->menu->parent != menu->parent) {
                        fprintf(stderr, "%s:%d: error: %s",
                                prop->filename, prop->lineno,
                                "choice value has a prompt outside its
choice group\n");






-- 
Best Regards
Masahiro Yamada

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-05-05 15:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-04 18:33 [PATCH 01/10] kconfig: gconf: redraw pane correctly after loading a config file Masahiro Yamada
2024-05-04 18:33 ` [PATCH 02/10] kconfig: gconf: remove debug code Masahiro Yamada
2024-05-04 18:33 ` [PATCH 03/10] kconfig: gconf: use MENU_CHANGED instead of SYMBOL_CHANGED Masahiro Yamada
2024-05-04 18:33 ` [PATCH 04/10] kconfig: used linked list in sym_set_changed() Masahiro Yamada
2024-05-04 18:33 ` [PATCH 05/10] kconfig: add sym_get_choice_menu() helper Masahiro Yamada
2024-05-04 18:33 ` [PATCH 06/10] kconfig: use sym_get_choice_menu() in conf_write_defconfig() Masahiro Yamada
2024-05-04 18:33 ` [PATCH 07/10] kconfig: use menu_list_for_each_sym() in sym_check_choice_deps() Masahiro Yamada
2024-05-04 18:33 ` [PATCH 08/10] kconfig: turn conf_choice() into void function Masahiro Yamada
2024-05-04 18:33 ` [PATCH 09/10] kconfig: turn missing prompt for choice members into error Masahiro Yamada
2024-05-04 18:33 ` [PATCH 10/10] kconfig: turn defaults and additional " Masahiro Yamada
2024-05-05 15:01   ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).