Skip to content

Commit 8a22f86

Browse files
committed
kconfig: turn defaults and additional prompt for choice members into error
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 <[email protected]>
1 parent 700e7a8 commit 8a22f86

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

scripts/kconfig/menu.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
507507
menu->sym && !sym_is_choice_value(menu->sym)) {
508508
current_entry = menu;
509509
menu->sym->flags |= SYMBOL_CHOICEVAL;
510-
for (prop = menu->sym->prop; prop; prop = prop->next) {
511-
if (prop->type == P_DEFAULT)
512-
prop_warn(prop, "defaults for choice "
513-
"values not supported");
514-
if (prop->menu == menu)
515-
continue;
516-
if (prop->type == P_PROMPT &&
517-
prop->menu->parent->sym != sym)
518-
prop_warn(prop, "choice value used outside its choice group");
519-
}
520510
/* Non-tristate choice values of tristate choices must
521511
* depend on the choice being set to Y. The choice
522512
* values' dependencies were propagated to their

scripts/kconfig/parser.y

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,38 @@ assign_val:
476476

477477
%%
478478

479+
/**
480+
* choice_check_sanity - check sanity of a choice member
481+
*
482+
* @menu: menu of the choice member
483+
*
484+
* Return: -1 if an error is found, 0 otherwise.
485+
*/
486+
static int choice_check_sanity(struct menu *menu)
487+
{
488+
struct property *prop;
489+
int ret = 0;
490+
491+
for (prop = menu->sym->prop; prop; prop = prop->next) {
492+
if (prop->type == P_DEFAULT) {
493+
fprintf(stderr, "%s:%d: error: %s",
494+
prop->filename, prop->lineno,
495+
"defaults for choice values not supported\n");
496+
ret = -1;
497+
}
498+
499+
if (prop->menu != menu && prop->type == P_PROMPT &&
500+
prop->menu->parent != menu->parent) {
501+
fprintf(stderr, "%s:%d: error: %s",
502+
prop->filename, prop->lineno,
503+
"choice value has a prompt outside its choice group\n");
504+
ret = -1;
505+
}
506+
}
507+
508+
return ret;
509+
}
510+
479511
void conf_parse(const char *name)
480512
{
481513
struct menu *menu;
@@ -523,8 +555,16 @@ void conf_parse(const char *name)
523555
menu_finalize();
524556

525557
menu_for_each_entry(menu) {
558+
struct menu *child;
559+
526560
if (menu->sym && sym_check_deps(menu->sym))
527561
yynerrs++;
562+
563+
if (menu->sym && sym_is_choice(menu->sym)) {
564+
menu_for_each_sub_entry(child, menu)
565+
if (child->sym && choice_check_sanity(child))
566+
yynerrs++;
567+
}
528568
}
529569

530570
if (yynerrs)

0 commit comments

Comments
 (0)