Skip to content

Commit f77850d

Browse files
ulfalizermasahir0y
authored andcommitted
kconfig: Clean up modules handling and fix crash
Kconfig currently doesn't handle 'm' appearing in a Kconfig file before the modules symbol is defined (the symbol with 'option modules'). The problem is the following code, which runs during parsing: /* change 'm' into 'm' && MODULES */ if (e->left.sym == &symbol_mod) return expr_alloc_and(e, expr_alloc_symbol(modules_sym)); If the modules symbol has not yet been defined, modules_sym is NULL, giving an invalid expression. Here is a test file where both BEFORE_1 and BEFORE_2 trigger a segfault. If the modules symbol is removed, all symbols trigger segfaults. config BEFORE_1 def_tristate y if m if m config BEFORE_2 def_tristate y endif config MODULES def_bool y option modules config AFTER_1 def_tristate y if m if m config AFTER_2 def_tristate y endif Fix the issue by rewriting 'm' in menu_finalize() instead. This function runs after parsing and is the proper place to do it. The following existing code in conf_parse() in zconf.y ensures that the modules symbol exists at that point: if (!modules_sym) modules_sym = sym_find( "n" ); ... menu_finalize(&rootmenu); The following tests were done to ensure no functional changes for configurations that don't reference 'm' before the modules symbol: - zconfdump(stdout) was run with ARCH=x86 and ARCH=arm before and after the change and verified to produce identical output. This function prints all symbols, choices, and menus together with their properties and their dependency expressions. A rewritten 'm' appears as 'm && MODULES'. A small annoyance is that the assert(len != 0) in xfwrite() needs to be disabled in order to use zconfdump(), because it chokes on e.g. 'default ""'. - The Kconfiglib test suite was run to indirectly verify that alldefconfig, allyesconfig, allnoconfig, and all defconfigs in the kernel still generate the same final .config. - Valgrind was used to check for memory errors and (new) memory leaks. Signed-off-by: Ulf Magnusson <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent fa8ceda commit f77850d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/kconfig/menu.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static struct expr *rewrite_m(struct expr *e)
110110

111111
void menu_add_dep(struct expr *dep)
112112
{
113-
current_entry->dep = expr_alloc_and(current_entry->dep, rewrite_m(dep));
113+
current_entry->dep = expr_alloc_and(current_entry->dep, dep);
114114
}
115115

116116
void menu_set_type(int type)
@@ -135,7 +135,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct
135135

136136
prop->menu = current_entry;
137137
prop->expr = expr;
138-
prop->visible.expr = rewrite_m(dep);
138+
prop->visible.expr = dep;
139139

140140
if (prompt) {
141141
if (isspace(*prompt)) {
@@ -340,7 +340,8 @@ void menu_finalize(struct menu *parent)
340340
* Propagate parent dependencies to the child menu
341341
* node, also rewriting and simplifying expressions
342342
*/
343-
basedep = expr_transform(menu->dep);
343+
basedep = rewrite_m(menu->dep);
344+
basedep = expr_transform(basedep);
344345
basedep = expr_alloc_and(expr_copy(parentdep), basedep);
345346
basedep = expr_eliminate_dups(basedep);
346347
menu->dep = basedep;
@@ -383,7 +384,8 @@ void menu_finalize(struct menu *parent)
383384
* property's condition, rewriting and
384385
* simplifying expressions at the same time
385386
*/
386-
dep = expr_transform(prop->visible.expr);
387+
dep = rewrite_m(prop->visible.expr);
388+
dep = expr_transform(dep);
387389
dep = expr_alloc_and(expr_copy(basedep), dep);
388390
dep = expr_eliminate_dups(dep);
389391
if (menu->sym && menu->sym->type != S_TRISTATE)

0 commit comments

Comments
 (0)