From: Dan Carpenter <dan.carpenter@oracle.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, namhyung@kernel.org, kan.liang@linux.intel.com,
zhe.he@windriver.com, dzickus@redhat.com, jstancek@redhat.com,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] perf cpumap: Use scnprintf instead of snprintf
Date: Mon, 23 Mar 2020 14:03:34 +0300 [thread overview]
Message-ID: <20200323110334.GC26299@kadam> (raw)
In-Reply-To: <20200322172523.2677-1-christophe.jaillet@wanadoo.fr>
On Sun, Mar 22, 2020 at 06:25:23PM +0100, Christophe JAILLET wrote:
> 'scnprintf' returns the number of characters written in the output buffer
> excluding the trailing '\0', instead of the number of characters which
> would be generated for the given input.
>
> Both function return a number of characters, excluding the trailing '\0'.
> So comparaison to check if it overflows, should be done against max_size-1.
> Comparaison against max_size can never match.
>
> Fixes: 7780c25bae59f ("perf tools: Allow ability to map cpus to nodes easily")
> Fixes: a24020e6b7cf6 ("perf tools: Change cpu_map__fprintf output")
> Fixes: 92a7e1278005b ("perf cpumap: Add cpu__max_present_cpu()")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> tools/perf/util/cpumap.c | 39 ++++++++++++++++++++-------------------
> 1 file changed, 20 insertions(+), 19 deletions(-)
>
> diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
> index 983b7388f22b..b87e7ef4d130 100644
> --- a/tools/perf/util/cpumap.c
> +++ b/tools/perf/util/cpumap.c
> @@ -316,8 +316,8 @@ static void set_max_cpu_num(void)
> goto out;
>
> /* get the highest possible cpu number for a sparse allocation */
> - ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
> - if (ret == PATH_MAX) {
> + ret = scnprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
> + if (ret == PATH_MAX-1) {
This should be a static analysis warning.
But isn't this stuff userspace? I can't figure out how to compile it on
Debian so I'm not sure. There is no scnprintf() in user space.
regards,
dan carpenter
next prev parent reply other threads:[~2020-03-23 11:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 17:25 [PATCH] perf cpumap: Use scnprintf instead of snprintf Christophe JAILLET
2020-03-23 11:03 ` Dan Carpenter [this message]
2020-03-23 12:08 ` Christophe JAILLET
2020-03-23 12:08 ` Christophe JAILLET
2020-03-23 12:16 ` Dan Carpenter
2020-03-23 15:11 ` David Laight
2020-03-23 15:20 ` Christophe JAILLET
2020-03-23 15:20 ` Christophe JAILLET
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=20200323110334.GC26299@kadam \
--to=dan.carpenter@oracle.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dzickus@redhat.com \
--cc=jolsa@redhat.com \
--cc=jstancek@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=zhe.he@windriver.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