[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180119091707.0a15a24d@gandalf.local.home>
Date: Fri, 19 Jan 2018 09:17:07 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc: Petr Mladek <pmladek@...e.com>, linux-kernel@...r.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Subject: Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
On Fri, 19 Jan 2018 13:39:01 +0900
Sergey Senozhatsky <sergey.senozhatsky.work@...il.com> wrote:
> We copy in null terminated strings "on" and "off", no
> need to zero out devkmsg_log_str in control_devkmsg().
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
> ---
> kernel/printk/printk.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index d70927c384f3..9faddcfd3994 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -136,13 +136,10 @@ static int __init control_devkmsg(char *str)
> /*
> * Set sysctl string accordingly:
> */
> - if (devkmsg_log == DEVKMSG_LOG_MASK_ON) {
> - memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
> - strncpy(devkmsg_log_str, "on", 2);
> - } else if (devkmsg_log == DEVKMSG_LOG_MASK_OFF) {
> - memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
> - strncpy(devkmsg_log_str, "off", 3);
> - }
> + if (devkmsg_log == DEVKMSG_LOG_MASK_ON)
> + strcpy(devkmsg_log_str, "on");
> + else if (devkmsg_log == DEVKMSG_LOG_MASK_OFF)
> + strcpy(devkmsg_log_str, "off");
> /* else "ratelimit" which is set by default. */
>
> /*
Yep, and even the sysctl checks for the terminating nul string, so
there's no leaks of any kind.
Tested by adding: printk.devkmsg=on and running:
$ hexdump -C /proc/sys/kernel/printk_devkmsg
00000000 6f 6e 0a |on.|
00000003
Reviewed-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
-- Steve
Powered by blists - more mailing lists