[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161130091427.GB18437@dhcp22.suse.cz>
Date: Wed, 30 Nov 2016 10:14:28 +0100
From: Michal Hocko <mhocko@...nel.org>
To: Sebastian Duda <sebastian.duda@....de>
Cc: linux-kernel@...cs.fau.de,
Tobias Baumeister <tobias.baumeister@....de>,
Andrew Morton <akpm@...ux-foundation.org>,
Petr Mladek <pmladek@...e.com>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Borislav Petkov <bp@...e.de>, Tejun Heo <tj@...nel.org>,
Thierry Reding <treding@...dia.com>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] printk.c: removed unnecessary code
[Resending with the full CC list as my email client has clobbered it in
the previous attempt for some reason]
On Tue 29-11-16 16:19:01, Sebastian Duda wrote:
> snprintf((char *) ?, 0, ...); always returns Zero and doesn't change the data.
> Thus the execution of
> snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
> has no effect on program.
> The substitution with 0 increases the readability of the code.
Are you sure this is correct. As per vsnprintf documentation:
"
* The return value is the number of characters which would
* be generated for the given input, excluding the trailing
* '\0', as per ISO C99.
"
this should just work as 35dac27cedd1 ("printk: fix incorrect length
from print_time() when seconds > 99999") intended.
I haven't checked the implementation though so I might be wrong here.
>
> Signed-off-by: Sebastian Duda <sebastian.duda@....de>
> Signed-off-by: Tobias Baumeister <tobias.baumeister@....de>
> ---
> kernel/printk/printk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 5028f4f..fe3fec1 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1186,7 +1186,7 @@ static size_t print_time(u64 ts, char *buf)
> rem_nsec = do_div(ts, 1000000000);
>
> if (!buf)
> - return snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
> + return 0;
>
> return sprintf(buf, "[%5lu.%06lu] ",
> (unsigned long)ts, rem_nsec / 1000);
> --
> 2.7.4
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists