public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org,
	Jules Irenge <jbi.octave@gmail.com>,
	x86@kernel.org
Subject: Re: [tip: perf/core] perf/core: Convert snprintf() to scnprintf()
Date: Wed, 21 Sep 2022 12:44:35 +0200	[thread overview]
Message-ID: <YyrrE8vpFSR+kdHQ@gmail.com> (raw)
In-Reply-To: <YyrMmyUPk+4t6OLm@hirez.programming.kicks-ass.net>


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Sep 21, 2022 at 08:08:55AM -0000, tip-bot2 for Jules Irenge wrote:
> > The following commit has been merged into the perf/core branch of tip:
> > 
> > Commit-ID:     678739d622ae7b75b62d550858b6bf104c43e2df
> > Gitweb:        https://git.kernel.org/tip/678739d622ae7b75b62d550858b6bf104c43e2df
> > Author:        Jules Irenge <jbi.octave@gmail.com>
> > AuthorDate:    Sun, 18 Sep 2022 00:41:08 +01:00
> > Committer:     Ingo Molnar <mingo@kernel.org>
> > CommitterDate: Wed, 21 Sep 2022 10:01:20 +02:00
> > 
> > perf/core: Convert snprintf() to scnprintf()
> > 
> > Coccinelle reports a warning:
> > 
> >     WARNING: use scnprintf or sprintf
> > 
> > Adding to that, there has also been some slow migration from snprintf to scnprintf.
> > 
> > This LWN article explains the rationale for this change:
> > 
> >     https: //lwn.net/Articles/69419/
> > 
> > No change in behavior.
> > 
> > [ mingo: Improved the changelog. ]
> 
> And yet, at this point I still have no clue what's wrong with
> snprintf(). So not much improvement :/

I've added this to the changelog:

    perf/core: Convert snprintf() to scnprintf()
    
    Coccinelle reports a warning:
    
        WARNING: use scnprintf or sprintf
    
    This LWN article explains the rationale for this change:
    
        https: //lwn.net/Articles/69419/
    
    Ie. snprintf() returns what *would* be the resulting length,
    while scnprintf() returns the actual length.
    
    Adding to that, there has also been some slow migration from snprintf to scnprintf,
    here's the shift in usage in the past 3.5 years, in all fs/ files:
    
                             v5.0    v6.0-rc6
       --------------------------------------
       snprintf() uses:        63         213
       scnprintf() uses:      374         186
    
    No intended change in behavior.

I also reviewed the usage sites - this patch could in fact be a bugfix as 
we are passing back these lengths to the VFS, which lengths are arguably 
bogus in the snprintf() case, should we ever get close to the buffer limits 
to trigger output truncation - which with PAGE_SIZE-1 is very unlikely.

[ Anyway, the shift in interface usage for FS code makes it pretty clear 
  that when in doubt we should use scnprintf() for FS code. snprintf() is 
  arguably actively dangerous whenever it works differently from sprintf() 
  ... ]

Thanks,

	Ingo

  reply	other threads:[~2022-09-21 10:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21  8:08 [tip: perf/core] perf/core: Convert snprintf() to scnprintf() tip-bot2 for Jules Irenge
2022-09-21  8:34 ` Peter Zijlstra
2022-09-21 10:44   ` Ingo Molnar [this message]
2022-09-21 12:55     ` David Sterba
2022-09-29  8:28       ` Jules Irenge
2022-09-21 11:58   ` Jules Irenge
  -- strict thread matches above, loose matches on Subject: below --
2022-09-21 10:40 tip-bot2 for Jules Irenge

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=YyrrE8vpFSR+kdHQ@gmail.com \
    --to=mingo@kernel.org \
    --cc=jbi.octave@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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