Commit f2211881 authored by Zhen Lei's avatar Zhen Lei Committed by Arnaldo Carvalho de Melo

perf data: Fix error return code in perf_data__create_dir()

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: default avatarHulk Robot <hulkci@huawei.com>
Signed-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210415083417.3740-1-thunder.leizhen@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7af08140
...@@ -35,7 +35,7 @@ void perf_data__close_dir(struct perf_data *data) ...@@ -35,7 +35,7 @@ void perf_data__close_dir(struct perf_data *data)
int perf_data__create_dir(struct perf_data *data, int nr) int perf_data__create_dir(struct perf_data *data, int nr)
{ {
struct perf_data_file *files = NULL; struct perf_data_file *files = NULL;
int i, ret = -1; int i, ret;
if (WARN_ON(!data->is_dir)) if (WARN_ON(!data->is_dir))
return -EINVAL; return -EINVAL;
...@@ -51,7 +51,8 @@ int perf_data__create_dir(struct perf_data *data, int nr) ...@@ -51,7 +51,8 @@ int perf_data__create_dir(struct perf_data *data, int nr)
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct perf_data_file *file = &files[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; goto out_err;
ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment