linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Peter Zijlstra <peterz@infradead.org>,
	Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Waiman Long <Waiman.Long@hp.com>,
	Stephane Eranian <eranian@google.com>,
	Jiri Olsa <jolsa@redhat.com>, David Ahern <dsahern@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf: Support for Openembedded/Yocto -dbg packages
Date: Wed, 2 Oct 2013 08:13:35 +0200	[thread overview]
Message-ID: <20131002061335.GD31122@gmail.com> (raw)
In-Reply-To: <87had0o5kf.fsf@sejong.aot.lge.com>


* Namhyung Kim <namhyung@kernel.org> wrote:

> Hi Ingo and Arnaldo,
> 
> On Wed, 18 Sep 2013 15:29:03 +0200, Ingo Molnar wrote:
> > * Arnaldo Carvalho de Melo <acme@ghostprotocols.net> wrote:
> >
> >> Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:
> >> > On Wed, Sep 18, 2013 at 12:02:12PM +0200, Ricardo Ribalda Delgado wrote:
> >> > > Perhaps this is even more clear than v2:
> >> 
> >> > > len = snprintf(file, size, "%s", symbol_conf.symfs);
> >> > > size -= len;
> >> > > file += len;
> >> > > len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2),
> >> > > "%s",  dso->long_name);
> >> > > size -= len;
> >> > > file += len;
> >> > > len = snprintf(file, size, ".debug%s",  last_slash);
> >> 
> >> > len = 0;
> >> 
> >> > len += snprintf(str + len, size - len, ...);
> >> > len += snprintf(str + len, size - len, ...);
> >> 
> >> And avoid snprintf like the plague, use scnprintf instead...  See
> >> e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)
> >
> > Hm, could we do:
> >
> > 	#define snprintf scnprintf
> >
> > or:
> >
> > 	#define snprintf(x...) BUILD_BUG()
> >
> > ?
> >
> > I don't think there's any valid code, except printf wrappers (which we 
> > don't have in perf), where the semantics of snprintf() would be needed.
> 
> There are some places that use snprintf() to query the actual length:
> 
> tools/perf/util/srcline.c:245:	size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
> tools/perf/util/values.c:147:		width = snprintf(NULL, 0, "%d", values->pid[i]);
> tools/perf/util/values.c:150:		width = snprintf(NULL, 0, "%d", values->tid[i]);
> tools/perf/util/values.c:154:			width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);
> tools/perf/util/values.c:189:		width = snprintf(NULL, 0, "%d", values->pid[i]);
> tools/perf/util/values.c:192:		width = snprintf(NULL, 0, "%d", values->tid[i]);
> tools/perf/util/values.c:200:		width = snprintf(NULL, 0, "%" PRIx64, values->counterrawid[j]);
> tools/perf/util/values.c:206:			width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);

I think that should be a separate, more obviously named helper inline 
instead, something like:

static inline printf_width(const char *fmt, ...)
{
        va_list args;
        int width;

        va_start(args, fmt);
        width = vsnprintf(NULL, 0, fmt, args);
        va_end(args);

        return width;
}

#define snprintf(fmt...) BUILD_BUG_ON(1, "Use scnprintf() instead of snprintf()")

or so? Then we could use it like this:

> tools/perf/util/values.c:147:		width = printf_width("%d", values->pid[i]);

and naked snprintf use would provoke a build bug.

Various printf wrappers can still use vsnprintf() - it's the routine use 
of snprintf() instead of scnprintf() that should be inhibited.

Thanks,

	Ingo

      reply	other threads:[~2013-10-02  6:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-18  8:43 [PATCH] perf: Support for Openembedded/Yocto -dbg packages Ricardo Ribalda Delgado
2013-09-18  9:24 ` Ingo Molnar
2013-09-18  9:47   ` Ricardo Ribalda Delgado
2013-09-18 10:02     ` Ricardo Ribalda Delgado
2013-09-18 10:18       ` Peter Zijlstra
2013-09-18 13:07         ` Arnaldo Carvalho de Melo
2013-09-18 13:29           ` Ingo Molnar
2013-09-18 13:58             ` Ricardo Ribalda Delgado
2013-09-18 14:08             ` Arnaldo Carvalho de Melo
2013-10-02  0:54             ` Namhyung Kim
2013-10-02  6:13               ` Ingo Molnar [this message]

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=20131002061335.GD31122@gmail.com \
    --to=mingo@kernel.org \
    --cc=Waiman.Long@hp.com \
    --cc=acme@ghostprotocols.net \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=ricardo.ribalda@gmail.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).