From f64048a20b0ce1bb1fd5c3f80e82556db73fe08b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:16 +0900 Subject: 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. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index d9d16469859a..b1b1ee8cf987 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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. */ -- cgit v1.2.3 From de026ca9152c3b3d8c85b8884a29040975ac1424 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:17 +0900 Subject: kconfig: use parent->dep as the parentdep of 'menu' In menu_finalize(), the dependency of a menu entry is propagated downwards. For the 'menu', parent->dep and parent->prompt->visible.expr have the same expression. Both accumulate the 'depends on' of itself and upper menu entries. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b1b1ee8cf987..bbabf0a59ac4 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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) { -- cgit v1.2.3 From 801b27db4638da1a7681865f2c6aab5270c5a29b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:18 +0900 Subject: kconfig: drop T_WORD from the RHS of 'prompt' symbol 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. Remove the T_WORD from the right-hand side of the symbol 'prompt'. Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index b3eff9613cf8..57f1225214cb 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -434,9 +434,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"; } -- cgit v1.2.3 From 1be6e791383a92e168662089dc956828dd33f0ff Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:19 +0900 Subject: kconfig: remove 'prompt' symbol Now that 'prompt' is only reduced from T_WORD_QUOTE without any action, use T_WORD_QUOTE directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 57f1225214cb..af770bf758ad 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -90,7 +90,6 @@ static struct menu *current_menu, *current_entry; %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL %nonassoc T_NOT -%type prompt %type nonconst_symbol %type symbol %type type logic_type default @@ -113,7 +112,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); }; @@ -181,7 +180,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()); @@ -265,7 +264,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()); @@ -334,7 +333,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); @@ -363,7 +362,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); @@ -372,7 +371,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); @@ -429,13 +428,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"; } | T_ENDIF T_EOL { $$ = "if"; } -- cgit v1.2.3 From 024352ff8d696e95a8601970f98a66d836e30549 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:20 +0900 Subject: kconfig: move prompt handling to menu_add_prompt() from menu_add_prop() 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(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 70 ++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index bbabf0a59ac4..45daece8d983 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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, -- cgit v1.2.3 From 2ffeef615b5e6ac452f55fd6277dc44a667c7c8c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:21 +0900 Subject: kconfig: remove 'prompt' argument from menu_add_prop() This function no longer uses the 'prompt' argument. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 45daece8d983..5a43784ded2c 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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) -- cgit v1.2.3 From 6397d96ba5a52c57ee1831a4ddc3aab01bb02048 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:22 +0900 Subject: kconfig: remove sym from struct property 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. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 1 - scripts/kconfig/parser.y | 2 +- scripts/kconfig/symbol.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 017843c9a4f4..6e102a3b8bd5 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -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; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index af770bf758ad..708b6c4b13ca 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -660,7 +660,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); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index f56eec5ea4c7..dbc5365d8bbc 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -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(); -- cgit v1.2.3 From adf7c5bd0674b04588246e444efef9987b2f1a6b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:14:23 +0900 Subject: kconfig: squash prop_alloc() into menu_add_prop() prop_alloc() is only called from menu_add_prop(). Squash it. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 18 +++++++++++++++++- scripts/kconfig/symbol.c | 21 --------------------- 3 files changed, 17 insertions(+), 23 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 4fb16f316626..73d3f01f1736 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -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) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 5a43784ded2c..8b772ced755d 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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 = ¤t_entry->sym->prop; + *propp; + propp = &(*propp)->next) + ; + *propp = prop; + } + return prop; } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index dbc5365d8bbc..8d38b700b314 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -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 || -- cgit v1.2.3 From 5edcef8454a4efb10a5cebdfbf284bcaf8b85451 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:16:36 +0900 Subject: kconfig: localmodconfig: remove unused $config This is unused since commit cdfc47950a53 ("kconfig: search for a config to base the local(mod|yes)config on"). Having unused $config is confusing because $config is used as a local variable in various sub-routines. Signed-off-by: Masahiro Yamada --- scripts/kconfig/streamline_config.pl | 2 -- 1 file changed, 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index 08d76d7b3b81..bbaa1e11a4e9 100755 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl @@ -56,8 +56,6 @@ sub dprint { print STDERR @_; } -my $config = ".config"; - my $uname = `uname -r`; chomp $uname; -- cgit v1.2.3 From 68f0d62746bc7d20c10a565a562baaf968d86415 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:16:37 +0900 Subject: kconfig: localmodconfig: fix indentation for closing brace This is the closing brace for the foreach loop. Fix the misleading indentation. Signed-off-by: Masahiro Yamada --- scripts/kconfig/streamline_config.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index bbaa1e11a4e9..e2f8504f5a2d 100755 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl @@ -372,7 +372,7 @@ if (defined($lsmod_file)) { $lsmod = "$dir/lsmod"; last; } -} + } if (!defined($lsmod)) { # try just the path $lsmod = "lsmod"; -- cgit v1.2.3 From 1d1352373ebcc627172132f261ea46df0cec767e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:18:18 +0900 Subject: kconfig: fix too deep indentation in Makefile The indentation for if ... else ... fi is too deep. Fix it. Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 2f1a59fa5169..f826a257d576 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -48,15 +48,15 @@ build_xconfig: $(obj)/qconf localyesconfig localmodconfig: $(obj)/conf $(Q)perl $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config - $(Q)if [ -f .config ]; then \ - cmp -s .tmp.config .config || \ - (mv -f .config .config.old.1; \ - mv -f .tmp.config .config; \ - $< $(silent) --oldconfig $(Kconfig); \ - mv -f .config.old.1 .config.old) \ - else \ - mv -f .tmp.config .config; \ - $< $(silent) --oldconfig $(Kconfig); \ + $(Q)if [ -f .config ]; then \ + cmp -s .tmp.config .config || \ + (mv -f .config .config.old.1; \ + mv -f .tmp.config .config; \ + $< $(silent) --oldconfig $(Kconfig); \ + mv -f .config.old.1 .config.old) \ + else \ + mv -f .tmp.config .config; \ + $< $(silent) --oldconfig $(Kconfig); \ fi $(Q)rm -f .tmp.config -- cgit v1.2.3 From c8138a57bbd1a13a2e23d34d3f8f338dd5b526ca Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 17 Dec 2019 13:18:19 +0900 Subject: kconfig: use $(PERL) in Makefile The top Makefile defines and exports the variable 'PERL'. Use it in case somebody wants to specify a particular version of perl from the command line. Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index f826a257d576..953a2859302c 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -47,7 +47,7 @@ build_gconfig: $(obj)/gconf build_xconfig: $(obj)/qconf localyesconfig localmodconfig: $(obj)/conf - $(Q)perl $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config + $(Q)$(PERL) $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config $(Q)if [ -f .config ]; then \ cmp -s .tmp.config .config || \ (mv -f .config .config.old.1; \ -- cgit v1.2.3 From 89b9060987d988333de59dd218c9666bd7ee95a5 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Tue, 17 Dec 2019 18:42:06 +0900 Subject: kconfig: Add yes2modconfig and mod2yesconfig targets. Since kernel configs provided by syzbot are close to "make allyesconfig", it takes long time to rebuild. This is especially waste of time when we need to rebuild for many times (e.g. doing manual printk() inspection, bisect operations). We can save time if we can exclude modules which are irrelevant to each problem. But "make localmodconfig" cannot exclude modules which are built into vmlinux because /sbin/lsmod output is used as the source of modules. Therefore, this patch adds "make yes2modconfig" which converts from =y to =m if possible. After confirming that the interested problem is still reproducible, we can try "make localmodconfig" (and/or manually tune based on "Modules linked in:" line) in order to exclude modules which are irrelevant to the interested problem. While we are at it, this patch also adds "make mod2yesconfig" which converts from =m to =y in case someone wants to convert from =m to =y after "make localmodconfig". Signed-off-by: Tetsuo Handa Cc: Dmitry Vyukov Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 4 +++- scripts/kconfig/conf.c | 16 ++++++++++++++++ scripts/kconfig/confdata.c | 16 ++++++++++++++++ scripts/kconfig/lkc.h | 3 +++ 4 files changed, 38 insertions(+), 1 deletion(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 953a2859302c..fbeb62ae3401 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -67,7 +67,7 @@ localyesconfig localmodconfig: $(obj)/conf # deprecated for external use simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \ alldefconfig randconfig listnewconfig olddefconfig syncconfig \ - helpnewconfig + helpnewconfig yes2modconfig mod2yesconfig PHONY += $(simple-targets) @@ -135,6 +135,8 @@ help: @echo ' allmodconfig - New config selecting modules when possible' @echo ' alldefconfig - New config with all symbols set to default' @echo ' randconfig - New config with random answer to all options' + @echo ' yes2modconfig - Change answers from yes to mod if possible' + @echo ' mod2yesconfig - Change answers from mod to yes if possible' @echo ' listnewconfig - List new options' @echo ' helpnewconfig - List new options and help text' @echo ' olddefconfig - Same as oldconfig but sets new symbols to their' diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 1f89bf1558ce..f6e548b8f795 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -34,6 +34,8 @@ enum input_mode { listnewconfig, helpnewconfig, olddefconfig, + yes2modconfig, + mod2yesconfig, }; static enum input_mode input_mode = oldaskconfig; @@ -467,6 +469,8 @@ static struct option long_opts[] = { {"listnewconfig", no_argument, NULL, listnewconfig}, {"helpnewconfig", no_argument, NULL, helpnewconfig}, {"olddefconfig", no_argument, NULL, olddefconfig}, + {"yes2modconfig", no_argument, NULL, yes2modconfig}, + {"mod2yesconfig", no_argument, NULL, mod2yesconfig}, {NULL, 0, NULL, 0} }; @@ -489,6 +493,8 @@ static void conf_usage(const char *progname) printf(" --allmodconfig New config where all options are answered with mod\n"); printf(" --alldefconfig New config with all symbols set to default\n"); printf(" --randconfig New config with random answer to all options\n"); + printf(" --yes2modconfig Change answers from yes to mod if possible\n"); + printf(" --mod2yesconfig Change answers from mod to yes if possible\n"); } int main(int ac, char **av) @@ -553,6 +559,8 @@ int main(int ac, char **av) case listnewconfig: case helpnewconfig: case olddefconfig: + case yes2modconfig: + case mod2yesconfig: break; case '?': conf_usage(progname); @@ -587,6 +595,8 @@ int main(int ac, char **av) case listnewconfig: case helpnewconfig: case olddefconfig: + case yes2modconfig: + case mod2yesconfig: conf_read(NULL); break; case allnoconfig: @@ -660,6 +670,12 @@ int main(int ac, char **av) break; case savedefconfig: break; + case yes2modconfig: + conf_rewrite_mod_or_yes(def_y2m); + break; + case mod2yesconfig: + conf_rewrite_mod_or_yes(def_m2y); + break; case oldaskconfig: rootEntry = &rootmenu; conf(&rootmenu); diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 3569d2dec37c..99f2418baa6c 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1362,3 +1362,19 @@ bool conf_set_all_new_symbols(enum conf_def_mode mode) return has_changed; } + +void conf_rewrite_mod_or_yes(enum conf_def_mode mode) +{ + struct symbol *sym; + int i; + tristate old_val = (mode == def_y2m) ? yes : mod; + tristate new_val = (mode == def_y2m) ? mod : yes; + + for_all_symbols(i, sym) { + if (sym_get_type(sym) == S_TRISTATE && + sym->def[S_DEF_USER].tri == old_val) { + sym->def[S_DEF_USER].tri = new_val; + sym_add_change_count(1); + } + } +} diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 73d3f01f1736..d4ca8297364f 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -34,6 +34,8 @@ enum conf_def_mode { def_default, def_yes, def_mod, + def_y2m, + def_m2y, def_no, def_random }; @@ -52,6 +54,7 @@ const char *conf_get_configname(void); void sym_set_change_count(int count); void sym_add_change_count(int count); bool conf_set_all_new_symbols(enum conf_def_mode mode); +void conf_rewrite_mod_or_yes(enum conf_def_mode mode); void set_all_choice_values(struct symbol *csym); /* confdata.c and expr.c */ -- cgit v1.2.3 From edda15f2197425c1aca8d1dd24a9bb3144686c7b Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Tue, 17 Dec 2019 08:15:43 -0800 Subject: kconfig: list all definitions of a symbol in help text In Kconfig, each symbol (representing a config option) can be defined in multiple places. Each definition may or may not have a prompt, which allows the option to be set via an interface like menuconfig. Each definition has a set of dependencies, which determine whether its prompt is visible and whether other pieces of the definition, like a default value, take effect. Historically, a symbol's help text (i.e. what's shown when a user presses '?' in menuconfig) contained some symbol-wide information not tied to any particular definition (e.g. what other symbols it selects) as well as the location (file name and line number) and dependencies of each prompt. Notably, the help text did not show the location or dependencies of definitions without prompts. Because this made it hard to reason about symbols that had no prompts, commit bcdedcc1afd6 ("menuconfig: print more info for symbol without prompts") changed the help text so that, instead of containing the location and dependencies of each prompt, it contained the location and dependencies of the symbol's first definition, regardless of whether or not that definition had a prompt. For symbols with only one definition, that change makes sense. However, it breaks down for symbols with multiple definitions: each definition has its own set of dependencies (the `dep` field of `struct menu`), and those dependencies are ORed together to get the symbol's dependency list (the `dir_dep` field of `struct symbol`). By printing only the dependencies of the first definition, the help text misleads users into believing that an option is more narrowly-applicable than it actually is. For an extreme example of this, we can look at the SYS_TEXT_BASE symbol in the Das U-Boot project (version 2019.10), which also uses Kconfig. (I unfortunately could not find an illustrative example in Linux.) This config option specifies the load address of the built binary and, as such, is applicable to basically every configuration possible. And yet, without this patch, its help text is as follows: Symbol: SYS_TEXT_BASE [=] Type : hex Prompt: U-Boot base address Location: -> ARM architecture Prompt: Text Base Location: -> Boot images Defined at arch/arm/mach-aspeed/Kconfig:9 Depends on: ARM [=n] && ARCH_ASPEED [=n] The help text indicates that the option is applicable only for a specific unselected architecture (aspeed), because that architecture's promptless definition (which just sets a default value), happens to be the first one seen. No definition or dependency information is printed for either of the two prompts listed. Because source locations and dependencies are fundamentally properties of definitions and not of symbols, we should treat them as such. This patch brings back the pre-bcdedcc1afd6 behavior for definitions with prompts but also separately prints the location and dependencies of those without prompts, solving the original problem in a different way. With this change, our SYS_TEXT_BASE example becomes Symbol: SYS_TEXT_BASE [=] Type : hex Defined at arch/arm/mach-stm32mp/Kconfig:83 Prompt: U-Boot base address Depends on: ARM [=n] && ARCH_STM32MP [=n] Location: -> ARM architecture Defined at Kconfig:532 Prompt: Text Base Depends on: !NIOS2 [=n] && !XTENSA [=n] && !EFI_APP [=n] Location: -> Boot images Defined at arch/arm/mach-aspeed/Kconfig:9 Depends on: ARM [=n] && ARCH_ASPEED [=n] Defined at arch/arm/mach-socfpga/Kconfig:25 Depends on: ARM [=n] && ARCH_SOCFPGA [=n] Defined at board/sifive/fu540/Kconfig:15 Depends on: RISCV [=n] && TARGET_SIFIVE_FU540 [=n] which is a much more accurate representation. Note that there is one notable difference between what gets printed for prompts after this change and what got printed before bcdedcc1afd6: the "Depends on" line now accurately represents the prompt's dependencies instead of conflating those with the prompt's visibility (which can include extra conditions). See the patch later in this series titled "kconfig: distinguish between dependencies and visibility in help text" for more details and better handling of that nuance. Signed-off-by: Thomas Hebb Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 55 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 8b772ced755d..b4fb0c88b6e0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -711,6 +711,21 @@ const char *menu_get_help(struct menu *menu) return ""; } +static void get_def_str(struct gstr *r, struct menu *menu) +{ + str_printf(r, "Defined at %s:%d\n", + menu->file->name, menu->lineno); +} + +static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) +{ + if (!expr_is_yes(expr)) { + str_append(r, prefix); + expr_gstr_print(expr, r); + str_append(r, "\n"); + } +} + static void get_prompt_str(struct gstr *r, struct property *prop, struct list_head *head) { @@ -718,7 +733,9 @@ static void get_prompt_str(struct gstr *r, struct property *prop, struct menu *submenu[8], *menu, *location = NULL; struct jump_key *jump = NULL; - str_printf(r, "Prompt: %s\n", prop->text); + str_printf(r, " Prompt: %s\n", prop->text); + + get_dep_str(r, prop->menu->dep, " Depends on: "); menu = prop->menu->parent; for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); @@ -768,18 +785,6 @@ static void get_prompt_str(struct gstr *r, struct property *prop, } } -/* - * get property of type P_SYMBOL - */ -static struct property *get_symbol_prop(struct symbol *sym) -{ - struct property *prop = NULL; - - for_all_properties(sym, prop, P_SYMBOL) - break; - return prop; -} - static void get_symbol_props_str(struct gstr *r, struct symbol *sym, enum prop_type tok, const char *prefix) { @@ -819,17 +824,19 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } } } - for_all_prompts(sym, prop) - get_prompt_str(r, prop, head); - - prop = get_symbol_prop(sym); - if (prop) { - str_printf(r, " Defined at %s:%d\n", prop->menu->file->name, - prop->menu->lineno); - if (!expr_is_yes(prop->visible.expr)) { - str_append(r, " Depends on: "); - expr_gstr_print(prop->visible.expr, r); - str_append(r, "\n"); + + /* Print the definitions with prompts before the ones without */ + for_all_properties(sym, prop, P_SYMBOL) { + if (prop->menu->prompt) { + get_def_str(r, prop->menu); + get_prompt_str(r, prop->menu->prompt, head); + } + } + + for_all_properties(sym, prop, P_SYMBOL) { + if (!prop->menu->prompt) { + get_def_str(r, prop->menu); + get_dep_str(r, prop->menu->dep, " Depends on: "); } } -- cgit v1.2.3 From 3460d0bc256a50b71dbdae8227c600761c502022 Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Tue, 17 Dec 2019 08:15:44 -0800 Subject: kconfig: distinguish between dependencies and visibility in help text Kconfig makes a distinction between dependencies (defined by "depends on" expressions and enclosing "if" blocks) and visibility (which includes all dependencies, but also includes inline "if" expressions of individual properties as well as, for prompts, "visible if" expressions of enclosing menus). Before commit bcdedcc1afd6 ("menuconfig: print more info for symbol without prompts"), the "Depends on" lines of a symbol's help text indicated the visibility of the prompt property they appeared under. After bcdedcc1afd, there was always only a single "Depends on" line, which indicated the visibility of the first P_SYMBOL property of the symbol. Since P_SYMBOLs never have inline if expressions, this was in effect the same as the dependencies of the menu item that the P_SYMBOL was attached to. Neither of these situations accurately conveyed the dependencies of a symbol--the first because it was actually the visibility, and the second because it only showed the dependencies from a single definition. With this series, we are back to printing separate dependencies for each definition, but we print the actual dependencies (rather than the visibility) in the "Depends on" line. However, it can still be useful to know the visibility of a prompt, so this patch adds a "Visible if" line that shows the visibility only if the visibility is different from the dependencies (which it isn't for most prompts in Linux). Before: Symbol: THUMB2_KERNEL [=n] Type : bool Defined at arch/arm/Kconfig:1417 Prompt: Compile the kernel in Thumb-2 mode Depends on: (CPU_V7 [=y] || CPU_V7M [=n]) && !CPU_V6 [=n] && !CPU_V6K [=n] Location: -> Kernel Features Selects: ARM_UNWIND [=n] After: Symbol: THUMB2_KERNEL [=n] Type : bool Defined at arch/arm/Kconfig:1417 Prompt: Compile the kernel in Thumb-2 mode Depends on: (CPU_V7 [=y] || CPU_V7M [=n]) && !CPU_V6 [=n] && !CPU_V6K [=n] Visible if: (CPU_V7 [=y] || CPU_V7M [=n]) && !CPU_V6 [=n] && !CPU_V6K [=n] && !CPU_THUMBONLY [=n] Location: -> Kernel Features Selects: ARM_UNWIND [=n] Signed-off-by: Thomas Hebb Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.c | 3 +-- scripts/kconfig/expr.h | 1 + scripts/kconfig/menu.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index 9f1de58e9f0c..81ebf8108ca7 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -13,7 +13,6 @@ #define DEBUG_EXPR 0 -static int expr_eq(struct expr *e1, struct expr *e2); static struct expr *expr_eliminate_yn(struct expr *e); struct expr *expr_alloc_symbol(struct symbol *sym) @@ -250,7 +249,7 @@ void expr_eliminate_eq(struct expr **ep1, struct expr **ep2) * equals some operand in the other (operands do not need to appear in the same * order), recursively. */ -static int expr_eq(struct expr *e1, struct expr *e2) +int expr_eq(struct expr *e1, struct expr *e2) { int res, old_count; diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 6e102a3b8bd5..5c3443692f34 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -300,6 +300,7 @@ struct expr *expr_alloc_or(struct expr *e1, struct expr *e2); struct expr *expr_copy(const struct expr *org); void expr_free(struct expr *e); void expr_eliminate_eq(struct expr **ep1, struct expr **ep2); +int expr_eq(struct expr *e1, struct expr *e2); tristate expr_calc_value(struct expr *e); struct expr *expr_trans_bool(struct expr *e); struct expr *expr_eliminate_dups(struct expr *e); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b4fb0c88b6e0..da50f79a8e8d 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -736,6 +736,17 @@ static void get_prompt_str(struct gstr *r, struct property *prop, str_printf(r, " Prompt: %s\n", prop->text); get_dep_str(r, prop->menu->dep, " Depends on: "); + /* + * Most prompts in Linux have visibility that exactly matches their + * dependencies. For these, we print only the dependencies to improve + * readability. However, prompts with inline "if" expressions and + * prompts with a parent that has a "visible if" expression have + * differing dependencies and visibility. In these rare cases, we + * print both. + */ + if (!expr_eq(prop->menu->dep, prop->visible.expr)) + get_dep_str(r, prop->visible.expr, " Visible if: "); + menu = prop->menu->parent; for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); -- cgit v1.2.3 From a9609686042b887baa636c77646b7614074c180a Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Tue, 17 Dec 2019 08:15:45 -0800 Subject: kconfig: fix nesting of symbol help text When we generate the help text of a symbol (e.g. when a user presses '?' in menuconfig), we do two things: 1. We iterate through every prompt that belongs to that symbol, printing its text and its location in the menu tree. 2. We print symbol-wide information that's not linked to a particular prompt, such as what it selects/is selected by and what it implies/is implied by. Each prompt we print for 1 starts with a line that's not indented indicating where the prompt is defined, then continues with indented lines that describe properties of that particular definition. Once we get to 2, however, we print all the global data indented as well! Visually, this makes it look like the symbol-wide data is associated with the last prompt we happened to print rather than the symbol as a whole. Fix this by removing the indentation for symbol-wide information. Before: Symbol: CPU_FREQ [=n] Type : bool Defined at drivers/cpufreq/Kconfig:4 Prompt: CPU Frequency scaling Location: -> CPU Power Management -> CPU Frequency scaling Selects: SRCU [=n] Selected by [n]: - ARCH_SA1100 [=n] && After: Symbol: CPU_FREQ [=n] Type : bool Defined at drivers/cpufreq/Kconfig:4 Prompt: CPU Frequency scaling Location: -> CPU Power Management -> CPU Frequency scaling Selects: SRCU [=n] Selected by [n]: - ARCH_SA1100 [=n] && Signed-off-by: Thomas Hebb Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index da50f79a8e8d..e436ba44c9c5 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -851,18 +851,18 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } } - get_symbol_props_str(r, sym, P_SELECT, " Selects: "); + get_symbol_props_str(r, sym, P_SELECT, "Selects: "); if (sym->rev_dep.expr) { - expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, " Selected by [y]:\n"); - expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, " Selected by [m]:\n"); - expr_gstr_print_revdep(sym->rev_dep.expr, r, no, " Selected by [n]:\n"); + expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, "Selected by [y]:\n"); + expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, "Selected by [m]:\n"); + expr_gstr_print_revdep(sym->rev_dep.expr, r, no, "Selected by [n]:\n"); } - get_symbol_props_str(r, sym, P_IMPLY, " Implies: "); + get_symbol_props_str(r, sym, P_IMPLY, "Implies: "); if (sym->implied.expr) { - expr_gstr_print_revdep(sym->implied.expr, r, yes, " Implied by [y]:\n"); - expr_gstr_print_revdep(sym->implied.expr, r, mod, " Implied by [m]:\n"); - expr_gstr_print_revdep(sym->implied.expr, r, no, " Implied by [n]:\n"); + expr_gstr_print_revdep(sym->implied.expr, r, yes, "Implied by [y]:\n"); + expr_gstr_print_revdep(sym->implied.expr, r, mod, "Implied by [m]:\n"); + expr_gstr_print_revdep(sym->implied.expr, r, no, "Implied by [n]:\n"); } str_append(r, "\n\n"); -- cgit v1.2.3 From ba82f52e2287f55ae10f4123980198b6ea8a8dc6 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 9 Jan 2020 17:16:36 +0100 Subject: kconfig: fix an "implicit declaration of function" warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strncasecmp() & strcasecmp() functions are declared in strings.h, not string.h. On most environments the former is implicitly included by the latter but on some setups, building menuconfig results in the following warning: HOSTCC scripts/kconfig/mconf.o scripts/kconfig/mconf.c: In function ‘search_conf’: scripts/kconfig/mconf.c:423:6: warning: implicit declaration of function ‘strncasecmp’ [-Wimplicit-function-declaration] if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0) ^~~~~~~~~~~ scripts/kconfig/mconf.c: In function ‘main’: scripts/kconfig/mconf.c:1021:8: warning: implicit declaration of function ‘strcasecmp’ [-Wimplicit-function-declaration] if (!strcasecmp(mode, "single_menu")) ^~~~~~~~~~ Fix it by explicitly including strings.h. Signed-off-by: Bartosz Golaszewski Signed-off-by: Masahiro Yamada --- scripts/kconfig/gconf.c | 1 + scripts/kconfig/mconf.c | 1 + scripts/kconfig/nconf.c | 1 + 3 files changed, 3 insertions(+) (limited to 'scripts/kconfig') diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c index e36b342f1065..5527482c3077 100644 --- a/scripts/kconfig/gconf.c +++ b/scripts/kconfig/gconf.c @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 49c26ea9dd98..4063dbc1b927 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index b7c1ef757178..daf1c1506ec4 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -8,6 +8,7 @@ #define _GNU_SOURCE #endif #include +#include #include #include "lkc.h" -- cgit v1.2.3