Re: [PATCH v4 15/31] kconfig: add 'info', 'warning', and 'error' built-in functions

Kees Cook
2018-05-17T06:38:57Z

On Wed, May 16, 2018 at 11:16 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Add 'info', 'warning', and 'error' functions as in Make.
>
> They print messages during parsing Kconfig files. 'error' will be
> useful to terminate the parsing immediately in fatal cases.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>
> Changes in v4:
> - Add 'error' function
>
> Changes in v3: None
> Changes in v2: None
>
> scripts/kconfig/preprocess.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
> index 47b32dc..591bcf7 100644
> --- a/scripts/kconfig/preprocess.c
> +++ b/scripts/kconfig/preprocess.c
> @@ -104,6 +104,20 @@ struct function {
> char *(*func)(int argc, char *argv[], int old_argc, char *old_argv[]);
> };
>
> +static char *do_error(int argc, char *argv[], int old_argc, char *old_argv[])
> +{
> + pperror("%s", argv[0]);
> +
> + return NULL;
> +}
> +
> +static char *do_info(int argc, char *argv[], int old_argc, char *old_argv[])
> +{
> + printf("%s\n", argv[0]);
> +
> + return xstrdup("");
> +}
> +
> static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[])
> {
> FILE *p;
> @@ -144,9 +158,19 @@ static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[])
> return xstrdup(buf);
> }
>
> +static char *do_warning(int argc, char *argv[], int old_argc, char *old_argv[])
> +{
> + fprintf(stderr, "%s:%d: %s\n", current_file->name, yylineno, argv[0]);
> +
> + return xstrdup("");
> +}
> +
> static const struct function function_table[] = {
> /* Name MIN MAX EXP? Function */
> + { "error", 1, 1, true, do_error },
> + { "info", 1, 1, true, do_info },
> { "shell", 1, 1, true, do_shell },
> + { "warning", 1, 1, true, do_warning },
> };
>
> #define FUNCTION_MAX_ARGS 16
> --
> 2.7.4
>

--
Kees Cook
Pixel Security