linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kconfig: improve handling EOF
@ 2014-12-19 15:20 Kirill A. Shutemov
  2014-12-19 17:07 ` Paul Bolle
  0 siblings, 1 reply; 2+ messages in thread
From: Kirill A. Shutemov @ 2014-12-19 15:20 UTC (permalink / raw)
  To: linux-kbuild, yann.morin.1998
  Cc: alexander.shishkin, linux-kernel, Kirill A. Shutemov

The patch fixes two EOF-related issues in kconfig lexer:

1. End of file is not valid end of string token. Currently we happily
   accept something like

	config FOO
		bool "Bar

   If there's EOF just after '"Bar' without newline.

2. Kconfig produces obscure error message if we miss newline at the end
   of file. Testcase:

	% echo -n 'if FOO\nendif' >> drivers/Kconfig
	% make allmodconfig
	...
	drivers/Kconfig:191: 'endif' in different file than 'if'
	drivers/Kconfig:191: location of the 'if'
	scripts/kconfig/Makefile:80: recipe for target 'allmodconfig' failed
	make[1]: *** [allmodconfig] Error 1
	Makefile:558: recipe for target 'allmodconfig' failed
	make: *** [allmodconfig] Error 2

   We can fix it if forbid EOF form <PARAM> context.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 kernel/Kconfig.preempt  | 2 +-
 scripts/kconfig/zconf.l | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index 3f9c97419f02..037284c5f723 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -55,4 +55,4 @@ config PREEMPT
 endchoice
 
 config PREEMPT_COUNT
-       bool
\ No newline at end of file
+       bool
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 6c62d93b4ffb..001abe8df6ce 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -143,7 +143,9 @@ n	[A-Za-z0-9_]
 	\\\n	current_file->lineno++;
 	.
 	<<EOF>> {
-		BEGIN(INITIAL);
+		printf("%s:%d: no newline at end of file\n",
+				zconf_curname(), zconf_lineno());
+		exit(1);
 	}
 }
 
@@ -179,7 +181,9 @@ n	[A-Za-z0-9_]
 		return T_EOL;
 	}
 	<<EOF>>	{
-		BEGIN(INITIAL);
+		printf("%s:%d: unexpected end of file\n",
+				zconf_curname(), zconf_lineno());
+		exit(1);
 	}
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kconfig: improve handling EOF
  2014-12-19 15:20 [PATCH] kconfig: improve handling EOF Kirill A. Shutemov
@ 2014-12-19 17:07 ` Paul Bolle
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Bolle @ 2014-12-19 17:07 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: linux-kbuild, yann.morin.1998, alexander.shishkin, linux-kernel

On Fri, 2014-12-19 at 17:20 +0200, Kirill A. Shutemov wrote:
> The patch fixes two EOF-related issues in kconfig lexer:
> 
> 1. End of file is not valid end of string token. Currently we happily
>    accept something like
> 
> 	config FOO
> 		bool "Bar
> 
>    If there's EOF just after '"Bar' without newline.
> 
> 2. Kconfig produces obscure error message if we miss newline at the end
>    of file. Testcase:
> 
> 	% echo -n 'if FOO\nendif' >> drivers/Kconfig
> 	% make allmodconfig
> 	...
> 	drivers/Kconfig:191: 'endif' in different file than 'if'
> 	drivers/Kconfig:191: location of the 'if'
> 	scripts/kconfig/Makefile:80: recipe for target 'allmodconfig' failed
> 	make[1]: *** [allmodconfig] Error 1
> 	Makefile:558: recipe for target 'allmodconfig' failed
> 	make: *** [allmodconfig] Error 2
> 
>    We can fix it if forbid EOF form <PARAM> context.

s/form/in/?

> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> ---
>  kernel/Kconfig.preempt  | 2 +-

This is actually the only Kconfig file that doesn't end in a newline,
isn't it?

>  scripts/kconfig/zconf.l | 8 ++++++--

Could you please regenerate the _shipped file too?

>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
> index 3f9c97419f02..037284c5f723 100644
> --- a/kernel/Kconfig.preempt
> +++ b/kernel/Kconfig.preempt
> @@ -55,4 +55,4 @@ config PREEMPT
>  endchoice
>  
>  config PREEMPT_COUNT
> -       bool
> \ No newline at end of file
> +       bool

This hunk is not described in the commit explanation. Besides, you
should do one thing per patch, so I think this should be a separate
patch. Trivial as it is (and non urgent, since this apparently never
broke the build.)

> diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
> index 6c62d93b4ffb..001abe8df6ce 100644
> --- a/scripts/kconfig/zconf.l
> +++ b/scripts/kconfig/zconf.l
> @@ -143,7 +143,9 @@ n	[A-Za-z0-9_]
>  	\\\n	current_file->lineno++;
>  	.
>  	<<EOF>> {
> -		BEGIN(INITIAL);
> +		printf("%s:%d: no newline at end of file\n",
> +				zconf_curname(), zconf_lineno());

Pet peeve of mine: warnings and errors should go to stderr.

> +		exit(1);

Not all missing newline-before-EOF are currently fatal, see
kernel/Kconfig.preempt above. So would this break the build even in
cases like that? That would mean one ill considered commit would break
the build. Perhaps we should warn and see whether we still can finish
the parse instead.

>  	}
>  }
>  
> @@ -179,7 +181,9 @@ n	[A-Za-z0-9_]
>  		return T_EOL;
>  	}
>  	<<EOF>>	{
> -		BEGIN(INITIAL);
> +		printf("%s:%d: unexpected end of file\n",
> +				zconf_curname(), zconf_lineno());

See above.

> +		exit(1);
>  	}
>  }
>  

See above.


Paul Bolle


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-19 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19 15:20 [PATCH] kconfig: improve handling EOF Kirill A. Shutemov
2014-12-19 17:07 ` Paul Bolle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).