public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kconfig: warn nested choice
@ 2019-12-17  4:02 Masahiro Yamada
  0 siblings, 0 replies; only message in thread
From: Masahiro Yamada @ 2019-12-17  4:02 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Ulf Magnusson, Masahiro Yamada, linux-kernel

If you create a 'choice' inside another 'choice', I do not know how
it should work.

I applied this patch onto v5.5-rc1, and I see one warning:

  drivers/usb/gadget/legacy/Kconfig:458: warning: nested choice. previous choice entry is drivers/usb/gadget/Kconfig:486

This is because entire drivers/usb/gadget/legacy/Kconfig is in the
choice context.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/parser.y | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index b3eff9613cf8..86e75ea74731 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -30,6 +30,9 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
 
 static struct menu *current_menu, *current_entry;
 
+/* while in the choice block, this points to the location of the choice entry */
+static struct menu *current_choice_menu;
+
 %}
 
 %union
@@ -239,6 +242,14 @@ choice: T_CHOICE word_opt T_EOL
 	menu_add_entry(sym);
 	menu_add_expr(P_CHOICE, NULL, NULL);
 	free($2);
+
+	if (current_choice_menu)
+		zconfprint("warning: nested choice. previous choice entry is %s:%d",
+			   current_choice_menu->file->name,
+			   current_choice_menu->lineno);
+
+	current_choice_menu = current_entry;
+
 	printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
 };
 
@@ -439,7 +450,7 @@ prompt:	  T_WORD
 ;
 
 end:	  T_ENDMENU T_EOL	{ $$ = "menu"; }
-	| T_ENDCHOICE T_EOL	{ $$ = "choice"; }
+	| T_ENDCHOICE T_EOL	{ $$ = "choice"; current_choice_menu = NULL; }
 	| T_ENDIF T_EOL		{ $$ = "if"; }
 ;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-17  4:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-17  4:02 [PATCH] kconfig: warn nested choice Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox