linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: Sebastian Duda <sebastian.duda@fau.de>,
	linux-kernel@i4.cs.fau.de,
	Tobias Baumeister <tobias.baumeister@fau.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Borislav Petkov <bp@suse.de>, Tejun Heo <tj@kernel.org>,
	Thierry Reding <treding@nvidia.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] printk.c: removed unnecessary code
Date: Wed, 30 Nov 2016 11:22:31 +0100	[thread overview]
Message-ID: <20161130102231.GE24060@pathway.suse.cz> (raw)
In-Reply-To: <20161130091427.GB18437@dhcp22.suse.cz>

On Wed 2016-11-30 10:14:28, Michal Hocko wrote:
> [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.

print_time() actually is not used by printk() directly. Therefore
the above reasoning does not apply.

They key here is to look when the buf might be NULL. It is when
we try to get an idea how much space will be needed for the message
when it is printed to some output device, e.g. console or syslog.
For example, there is the following chain of calls:

  syslog_print_all()
     msg_print_text(msg, prev, true, NULL, 0)
       print_prefix(msg, syslog, NULL)
         len += print_time(msg->ts_nsec, buf ? buf + len : NULL)

It means that we really need to know the length of the printed
string even when we do not write it to a buffer for the moment.

By other words, the patch would break the functionality.

> > 
> > Signed-off-by: Sebastian Duda <sebastian.duda@fau.de>
> > Signed-off-by: Tobias Baumeister <tobias.baumeister@fau.de>

Nacked-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

  reply	other threads:[~2016-11-30 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 15:19 [PATCH] printk.c: removed unnecessary code Sebastian Duda
2016-11-30  9:14 ` Michal Hocko
2016-11-30 10:22   ` Petr Mladek [this message]
2016-12-01 17:12 ` [lkp] [printk.c] ea0639c4d5: BUG:recent_printk_recursion kernel test robot
2016-12-02 10:05   ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161130102231.GE24060@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@suse.de \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@kernel.org \
    --cc=sebastian.duda@fau.de \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tj@kernel.org \
    --cc=tobias.baumeister@fau.de \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).