All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] perf data: Fix error return code in perf_data__create_dir()
Date: Mon, 19 Apr 2021 14:14:31 -0300	[thread overview]
Message-ID: <YH26d0r10woPIoFB@kernel.org> (raw)
In-Reply-To: <YHglwGXW7IV4W6qV@krava>

Em Thu, Apr 15, 2021 at 01:38:40PM +0200, Jiri Olsa escreveu:
> On Thu, Apr 15, 2021 at 04:34:16PM +0800, Zhen Lei wrote:
> > Although 'ret' has been initialized to -1, but it will be reassigned by
> > the "ret = open(...)" statement in the for loop. So that, the value of
> > 'ret' is unknown when asprintf() failed.
> > 
> > Reported-by: Hulk Robot <hulkci@huawei.com>
> > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> 
> Acked-by: Jiri Olsa <jolsa@redhat.com>

Thanks, applied.

- Arnaldo

 
> thanks,
> jirka
> 
> > ---
> >  tools/perf/util/data.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> > index f29af4fc3d09390..8fca4779ae6a8e9 100644
> > --- a/tools/perf/util/data.c
> > +++ b/tools/perf/util/data.c
> > @@ -35,7 +35,7 @@ void perf_data__close_dir(struct perf_data *data)
> >  int perf_data__create_dir(struct perf_data *data, int nr)
> >  {
> >  	struct perf_data_file *files = NULL;
> > -	int i, ret = -1;
> > +	int i, ret;
> >  
> >  	if (WARN_ON(!data->is_dir))
> >  		return -EINVAL;
> > @@ -51,7 +51,8 @@ int perf_data__create_dir(struct perf_data *data, int nr)
> >  	for (i = 0; i < nr; i++) {
> >  		struct perf_data_file *file = &files[i];
> >  
> > -		if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0)
> > +		ret = asprintf(&file->path, "%s/data.%d", data->path, i);
> > +		if (ret < 0)
> >  			goto out_err;
> >  
> >  		ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
> > -- 
> > 2.26.0.106.g9fadedd
> > 
> > 
> 

-- 

- Arnaldo

      reply	other threads:[~2021-04-19 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15  8:34 [PATCH 1/1] perf data: Fix error return code in perf_data__create_dir() Zhen Lei
2021-04-15 11:38 ` Jiri Olsa
2021-04-19 17:14   ` Arnaldo Carvalho de Melo [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=YH26d0r10woPIoFB@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=thunder.leizhen@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.