Skip to contentSkip to conversation

kconfig: misc cleanups

PATCH In review Masahiro Yamada 1 participant 10 messages Dec 17, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover kconfig: misc cleanups

Masahiro Yamada (8):
kconfig: remove the rootmenu check in menu_add_prop()
kconfig: use parent->dep as the parentdep of 'menu'
kconfig: drop T_WORD from the RHS of 'prompt' symbol
kconfig: remove 'prompt' symbol
kconfig: move prompt handling to menu_add_prompt() from

    menu_add_prop()

kconfig: remove 'prompt' argument from menu_add_prop()
kconfig: remove sym from struct property
kconfig: squash prop_alloc() into menu_add_prop()

 scripts/kconfig/expr.h   |   1 -
 scripts/kconfig/lkc.h    |   1 -
 scripts/kconfig/menu.c   | 103 ++++++++++++++++++++++-----------------
 scripts/kconfig/parser.y |  21 +++-----
 scripts/kconfig/symbol.c |  22 ---------
 5 files changed, 66 insertions(+), 82 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/8 kconfig: remove the rootmenu check in menu_add_prop()

This reverts commit ba6ff60d5eb4 ("kconfig: don't emit warning upon rootmenu's prompt redefinition").

At that time, rootmenu.prompt was always set first, then it was set again if a "mainmenu" statement was specified in the Kconfig file.

This is no longer the case since commit 0724a7c32a54 ("kconfig: Don't leak main menus during parsing"). Remove the unneeded check.

---

 scripts/kconfig/menu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/menu.c +1 -1
index d9d16469859a..b1b1ee8cf987 100644
@@ -138,7 +138,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct
 			while (isspace(*prompt))
 				prompt++;
 		}
-		if (current_entry->prompt && current_entry != &rootmenu)
+		if (current_entry->prompt)
 			prop_warn(prop, "prompt redefined");
 
 		/* Apply all upper menus' visibilities to actual prompts. */
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/8 kconfig: use parent->dep as the parentdep of 'menu'

In reply to Masahiro Yamada

In menu_finalize(), the dependency of a menu entry is propagated downwards.

For the 'menu', ->dep and ->prompt->visible.expr are the same. Both accumulate the 'depends on' of itself and upper menu entries.

---

 scripts/kconfig/menu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/kconfig/menu.c +3 -5
index b1b1ee8cf987..bbabf0a59ac4 100644
@@ -326,12 +326,10 @@ void menu_finalize(struct menu *parent)
 			 * choice value symbols.
 			 */
 			parentdep = expr_alloc_symbol(sym);
-		} else if (parent->prompt)
-			/* Menu node for 'menu' */
-			parentdep = parent->prompt->visible.expr;
-		else
-			/* Menu node for 'if' */
+		} else {
+			/* Menu node for 'menu', 'if' */
 			parentdep = parent->dep;
+		}
 
 		/* For each child menu node... */
 		for (menu = parent->list; menu; menu = menu->next) {
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/8] kconfig: use parent->dep as the parentdep of 'menu'

Quoted 5 lines · Masahiro Yamada

In menu_finalize(), the dependency of a menu entry is propagated downwards.

For the 'menu', ->dep and ->prompt->visible.expr are the same.

Just for clarification, this means
parent->dep and parent->prompt->visible.expr
have the same expression.

expr_eq(parent->dep, parent->prompt->visible.expr) should return 1.

Quoted 31 lines

Both accumulate the 'depends on' of itself and upper menu entries.

---

 scripts/kconfig/menu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/kconfig/menu.c +3 -6
index b1b1ee8cf987..bbabf0a59ac4 100644
@@ -326,12 +326,10 @@ void menu_finalize(struct menu *parent)
                         * choice value symbols.
                         */
                        parentdep = expr_alloc_symbol(sym);
-               } else if (parent->prompt)
-                       /* Menu node for 'menu' */
-                       parentdep = parent->prompt->visible.expr;
-               else
-                       /* Menu node for 'if' */
+               } else {
+                       /* Menu node for 'menu', 'if' */
                        parentdep = parent->dep;
+               }
 
                /* For each child menu node... */
                for (menu = parent->list; menu; menu = menu->next) {
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#4 lore raw

PATCH 3/8 kconfig: drop T_WORD from the RHS of 'prompt' symbol

In reply to Masahiro Yamada

Commit 8636a1f9677d ("treewide: surround Kconfig file paths with double quotes") killed use-cases to reduce an unquoted string into the 'prompt' symbol.

Kconfig still allows to use an unquoted string in the context of menu, source, or prompt.

So, you can omit quoting if the prompt is a single word:

bool foo

..., but I do not think this is so useful.

Let's require quoting:

bool "foo"

All the Kconfig files in the kernel are written in this way.

---

 scripts/kconfig/parser.y | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
scripts/kconfig/parser.y +1 -3
index 86e75ea74731..80585f04f590 100644
@@ -445,9 +445,7 @@ prompt_stmt_opt:
 	menu_add_prompt(P_PROMPT, $1, $2);
 };
 
-prompt:	  T_WORD
-	| T_WORD_QUOTE
-;
+prompt:	  T_WORD_QUOTE
 
 end:	  T_ENDMENU T_EOL	{ $$ = "menu"; }
 	| T_ENDCHOICE T_EOL	{ $$ = "choice"; current_choice_menu = NULL; }
Signature · 1 line
2.17.1
#5 lore raw

PATCH 4/8 kconfig: remove 'prompt' symbol

In reply to Masahiro Yamada

Now that 'prompt' is only reduced from T_WORD_QUOTE without any action, use T_WORD_QUOTE directly.

---

 scripts/kconfig/parser.y | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
scripts/kconfig/parser.y +7 -10
index 80585f04f590..40e46996e6a5 100644
@@ -93,7 +93,6 @@ static struct menu *current_choice_menu;
 %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
 %nonassoc T_NOT
 
-%type <string> prompt
 %type <symbol> nonconst_symbol
 %type <symbol> symbol
 %type <type> type logic_type default
@@ -116,7 +115,7 @@ input: mainmenu_stmt stmt_list | stmt_list;
 
 /* mainmenu entry */
 
-mainmenu_stmt: T_MAINMENU prompt T_EOL
+mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL
 {
 	menu_add_prompt(P_MENU, $2, NULL);
 };
@@ -184,7 +183,7 @@ config_option: type prompt_stmt_opt T_EOL
 		$1);
 };
 
-config_option: T_PROMPT prompt if_expr T_EOL
+config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
 {
 	menu_add_prompt(P_PROMPT, $2, $3);
 	printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
@@ -276,7 +275,7 @@ choice_option_list:
 	| choice_option_list help
 ;
 
-choice_option: T_PROMPT prompt if_expr T_EOL
+choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
 {
 	menu_add_prompt(P_PROMPT, $2, $3);
 	printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
@@ -345,7 +344,7 @@ if_stmt: if_entry stmt_list if_end
 
 /* menu entry */
 
-menu: T_MENU prompt T_EOL
+menu: T_MENU T_WORD_QUOTE T_EOL
 {
 	menu_add_entry(NULL);
 	menu_add_prompt(P_MENU, $2, NULL);
@@ -374,7 +373,7 @@ menu_option_list:
 	| menu_option_list depends
 ;
 
-source_stmt: T_SOURCE prompt T_EOL
+source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
 {
 	printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
 	zconf_nextfile($2);
@@ -383,7 +382,7 @@ source_stmt: T_SOURCE prompt T_EOL
 
 /* comment entry */
 
-comment: T_COMMENT prompt T_EOL
+comment: T_COMMENT T_WORD_QUOTE T_EOL
 {
 	menu_add_entry(NULL);
 	menu_add_prompt(P_COMMENT, $2, NULL);
@@ -440,13 +439,11 @@ visible: T_VISIBLE if_expr T_EOL
 
 prompt_stmt_opt:
 	  /* empty */
-	| prompt if_expr
+	| T_WORD_QUOTE if_expr
 {
 	menu_add_prompt(P_PROMPT, $1, $2);
 };
 
-prompt:	  T_WORD_QUOTE
-
 end:	  T_ENDMENU T_EOL	{ $$ = "menu"; }
 	| T_ENDCHOICE T_EOL	{ $$ = "choice"; current_choice_menu = NULL; }
 	| T_ENDIF T_EOL		{ $$ = "if"; }
Signature · 1 line
2.17.1
#6 lore raw

PATCH 5/8 kconfig: move prompt handling to menu_add_prompt() from menu_add_prop()

In reply to Masahiro Yamada

menu_add_prompt() is the only function that calls menu_add_prop() with non-NULL prompt.

So, the code inside the if-conditional block of menu_add_prop() can be moved to menu_add_prompt().

---

 scripts/kconfig/menu.c | 70 ++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 36 deletions(-)
scripts/kconfig/menu.c +34 -36
index bbabf0a59ac4..45daece8d983 100644
@@ -132,53 +132,51 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct
 	prop->expr = expr;
 	prop->visible.expr = dep;
 
-	if (prompt) {
-		if (isspace(*prompt)) {
-			prop_warn(prop, "leading whitespace ignored");
-			while (isspace(*prompt))
-				prompt++;
-		}
-		if (current_entry->prompt)
-			prop_warn(prop, "prompt redefined");
+	return prop;
+}
 
-		/* Apply all upper menus' visibilities to actual prompts. */
-		if(type == P_PROMPT) {
-			struct menu *menu = current_entry;
+struct property *menu_add_prompt(enum prop_type type, char *prompt,
+				 struct expr *dep)
+{
+	struct property *prop = menu_add_prop(type, prompt, NULL, dep);
 
-			while ((menu = menu->parent) != NULL) {
-				struct expr *dup_expr;
+	if (isspace(*prompt)) {
+		prop_warn(prop, "leading whitespace ignored");
+		while (isspace(*prompt))
+			prompt++;
+	}
+	if (current_entry->prompt)
+		prop_warn(prop, "prompt redefined");
 
-				if (!menu->visibility)
-					continue;
-				/*
-				 * Do not add a reference to the
-				 * menu's visibility expression but
-				 * use a copy of it.  Otherwise the
-				 * expression reduction functions
-				 * will modify expressions that have
-				 * multiple references which can
-				 * cause unwanted side effects.
-				 */
-				dup_expr = expr_copy(menu->visibility);
+	/* Apply all upper menus' visibilities to actual prompts. */
+	if (type == P_PROMPT) {
+		struct menu *menu = current_entry;
 
-				prop->visible.expr
-					= expr_alloc_and(prop->visible.expr,
-							 dup_expr);
-			}
-		}
+		while ((menu = menu->parent) != NULL) {
+			struct expr *dup_expr;
 
-		current_entry->prompt = prop;
+			if (!menu->visibility)
+				continue;
+			/*
+			 * Do not add a reference to the menu's visibility
+			 * expression but use a copy of it. Otherwise the
+			 * expression reduction functions will modify
+			 * expressions that have multiple references which
+			 * can cause unwanted side effects.
+			 */
+			dup_expr = expr_copy(menu->visibility);
+
+			prop->visible.expr = expr_alloc_and(prop->visible.expr,
+							    dup_expr);
+		}
 	}
+
+	current_entry->prompt = prop;
 	prop->text = prompt;
 
 	return prop;
 }
 
-struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep)
-{
-	return menu_add_prop(type, prompt, NULL, dep);
-}
-
 void menu_add_visibility(struct expr *expr)
 {
 	current_entry->visibility = expr_alloc_and(current_entry->visibility,
Signature · 1 line
2.17.1
#7 lore raw

PATCH 6/8 kconfig: remove 'prompt' argument from menu_add_prop()

In reply to Masahiro Yamada

This function does not use the 'prompt' argument.

---

 scripts/kconfig/menu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/kconfig/menu.c +5 -4
index 45daece8d983..5a43784ded2c 100644
@@ -124,7 +124,8 @@ void menu_set_type(int type)
 		sym_type_name(sym->type), sym_type_name(type));
 }
 
-static struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep)
+static struct property *menu_add_prop(enum prop_type type, struct expr *expr,
+				      struct expr *dep)
 {
 	struct property *prop = prop_alloc(type, current_entry->sym);
 
@@ -138,7 +139,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct
 struct property *menu_add_prompt(enum prop_type type, char *prompt,
 				 struct expr *dep)
 {
-	struct property *prop = menu_add_prop(type, prompt, NULL, dep);
+	struct property *prop = menu_add_prop(type, NULL, dep);
 
 	if (isspace(*prompt)) {
 		prop_warn(prop, "leading whitespace ignored");
@@ -185,12 +186,12 @@ void menu_add_visibility(struct expr *expr)
 
 void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
 {
-	menu_add_prop(type, NULL, expr, dep);
+	menu_add_prop(type, expr, dep);
 }
 
 void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
 {
-	menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
+	menu_add_prop(type, expr_alloc_symbol(sym), dep);
 }
 
 void menu_add_option_modules(void)
Signature · 1 line
2.17.1
#8 lore raw

PATCH 7/8 kconfig: remove sym from struct property

In reply to Masahiro Yamada

struct property can reference to the symbol that it is associated with by prop->menu->sym.

Fix up the one usage of prop->sym, and remove sym from struct property.

---

 scripts/kconfig/expr.h   | 1 -
 scripts/kconfig/parser.y | 2 +-
 scripts/kconfig/symbol.c | 1 -
 3 files changed, 1 insertion(+), 3 deletions(-)
scripts/kconfig/expr.h +0 -1
index 017843c9a4f4..6e102a3b8bd5 100644
@@ -191,7 +191,6 @@ enum prop_type {
 
 struct property {
 	struct property *next;     /* next property - null if last */
-	struct symbol *sym;        /* the symbol for which the property is associated */
 	enum prop_type type;       /* type of property */
 	const char *text;          /* the prompt value - P_PROMPT, P_MENU, P_COMMENT */
 	struct expr_value visible;
scripts/kconfig/parser.y +1 -1
index 40e46996e6a5..d5c41a5c370c 100644
@@ -671,7 +671,7 @@ static void print_symbol(FILE *out, struct menu *menu)
 			break;
 		case P_SYMBOL:
 			fputs( "  symbol ", out);
-			fprintf(out, "%s\n", prop->sym->name);
+			fprintf(out, "%s\n", prop->menu->sym->name);
 			break;
 		default:
 			fprintf(out, "  unknown prop %d!\n", prop->type);
scripts/kconfig/symbol.c +0 -1
index f56eec5ea4c7..dbc5365d8bbc 100644
@@ -1281,7 +1281,6 @@ struct property *prop_alloc(enum prop_type type, struct symbol *sym)
 	prop = xmalloc(sizeof(*prop));
 	memset(prop, 0, sizeof(*prop));
 	prop->type = type;
-	prop->sym = sym;
 	prop->file = current_file;
 	prop->lineno = zconf_lineno();
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 8/8 kconfig: squash prop_alloc() into menu_add_prop()

In reply to Masahiro Yamada

prop_alloc() is only called from menu_add_prop(). Squash it.

---

 scripts/kconfig/lkc.h    |  1 -
 scripts/kconfig/menu.c   | 18 +++++++++++++++++-
 scripts/kconfig/symbol.c | 21 ---------------------
 3 files changed, 17 insertions(+), 23 deletions(-)
scripts/kconfig/lkc.h +0 -1
index 4fb16f316626..73d3f01f1736 100644
@@ -112,7 +112,6 @@ struct symbol *sym_choice_default(struct symbol *sym);
 struct property *sym_get_range_prop(struct symbol *sym);
 const char *sym_get_string_default(struct symbol *sym);
 struct symbol *sym_check_deps(struct symbol *sym);
-struct property *prop_alloc(enum prop_type type, struct symbol *sym);
 struct symbol *prop_get_symbol(struct property *prop);
 
 static inline tristate sym_get_tristate_value(struct symbol *sym)
scripts/kconfig/menu.c +17 -1
index 5a43784ded2c..8b772ced755d 100644
@@ -127,12 +127,28 @@ void menu_set_type(int type)
 static struct property *menu_add_prop(enum prop_type type, struct expr *expr,
 				      struct expr *dep)
 {
-	struct property *prop = prop_alloc(type, current_entry->sym);
+	struct property *prop;
 
+	prop = xmalloc(sizeof(*prop));
+	memset(prop, 0, sizeof(*prop));
+	prop->type = type;
+	prop->file = current_file;
+	prop->lineno = zconf_lineno();
 	prop->menu = current_entry;
 	prop->expr = expr;
 	prop->visible.expr = dep;
 
+	/* append property to the prop list of symbol */
+	if (current_entry->sym) {
+		struct property **propp;
+
+		for (propp = &current_entry->sym->prop;
+		     *propp;
+		     propp = &(*propp)->next)
+			;
+		*propp = prop;
+	}
+
 	return prop;
 }
 
scripts/kconfig/symbol.c +0 -21
index dbc5365d8bbc..8d38b700b314 100644
@@ -1273,27 +1273,6 @@ struct symbol *sym_check_deps(struct symbol *sym)
 	return sym2;
 }
 
-struct property *prop_alloc(enum prop_type type, struct symbol *sym)
-{
-	struct property *prop;
-	struct property **propp;
-
-	prop = xmalloc(sizeof(*prop));
-	memset(prop, 0, sizeof(*prop));
-	prop->type = type;
-	prop->file = current_file;
-	prop->lineno = zconf_lineno();
-
-	/* append property to the prop list of symbol */
-	if (sym) {
-		for (propp = &sym->prop; *propp; propp = &(*propp)->next)
-			;
-		*propp = prop;
-	}
-
-	return prop;
-}
-
 struct symbol *prop_get_symbol(struct property *prop)
 {
 	if (prop->expr && (prop->expr->type == E_SYMBOL ||
Signature · 1 line
2.17.1