Skip to content

Commit 246cf9c

Browse files
ctmarinasmichal42
authored andcommitted
kbuild: Warn on selecting symbols with unmet direct dependencies
The "select" statement in Kconfig files allows the enabling of options even if they have unmet direct dependencies (i.e. "depends on" expands to "no"). Currently, the "depends on" clauses are used in calculating the visibility but they do not affect the reverse dependencies in any way. The patch introduces additional tracking of the "depends on" statements and prints a warning on selecting an option if its direct dependencies are not met. Signed-off-by: Catalin Marinas <[email protected]> Cc: Sam Ravnborg <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Linus Torvalds <[email protected]> Signed-off-by: Michal Marek <[email protected]>
1 parent 60c8eca commit 246cf9c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

scripts/kconfig/expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct symbol {
8383
tristate visible;
8484
int flags;
8585
struct property *prop;
86+
struct expr_value dir_dep;
8687
struct expr_value rev_dep;
8788
};
8889

@@ -163,6 +164,7 @@ struct menu {
163164
struct symbol *sym;
164165
struct property *prompt;
165166
struct expr *dep;
167+
struct expr *dir_dep;
166168
unsigned int flags;
167169
char *help;
168170
struct file *file;

scripts/kconfig/menu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static struct expr *menu_check_dep(struct expr *e)
105105
void menu_add_dep(struct expr *dep)
106106
{
107107
current_entry->dep = expr_alloc_and(current_entry->dep, menu_check_dep(dep));
108+
current_entry->dir_dep = current_entry->dep;
108109
}
109110

110111
void menu_set_type(int type)
@@ -288,6 +289,10 @@ void menu_finalize(struct menu *parent)
288289
for (menu = parent->list; menu; menu = menu->next)
289290
menu_finalize(menu);
290291
} else if (sym) {
292+
/* ignore inherited dependencies for dir_dep */
293+
sym->dir_dep.expr = expr_transform(expr_copy(parent->dir_dep));
294+
sym->dir_dep.expr = expr_eliminate_dups(sym->dir_dep.expr);
295+
291296
basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
292297
basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
293298
basedep = expr_eliminate_dups(expr_transform(basedep));

scripts/kconfig/symbol.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ static void sym_calc_visibility(struct symbol *sym)
205205
}
206206
if (sym_is_choice_value(sym))
207207
return;
208+
/* defaulting to "yes" if no explicit "depends on" are given */
209+
tri = yes;
210+
if (sym->dir_dep.expr)
211+
tri = expr_calc_value(sym->dir_dep.expr);
212+
if (tri == mod)
213+
tri = yes;
214+
if (sym->dir_dep.tri != tri) {
215+
sym->dir_dep.tri = tri;
216+
sym_set_changed(sym);
217+
}
208218
tri = no;
209219
if (sym->rev_dep.expr)
210220
tri = expr_calc_value(sym->rev_dep.expr);
@@ -321,6 +331,14 @@ void sym_calc_value(struct symbol *sym)
321331
}
322332
}
323333
calc_newval:
334+
if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) {
335+
fprintf(stderr, "warning: (");
336+
expr_fprint(sym->rev_dep.expr, stderr);
337+
fprintf(stderr, ") selects %s which has unmet direct dependencies (",
338+
sym->name);
339+
expr_fprint(sym->dir_dep.expr, stderr);
340+
fprintf(stderr, ")\n");
341+
}
324342
newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
325343
}
326344
if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)

0 commit comments

Comments
 (0)