Skip to content

Commit f221188

Browse files
Zhen Leiacmel
authored andcommitted
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: Hulk Robot <[email protected]> Signed-off-by: Zhen Lei <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7af0814 commit f221188

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/perf/util/data.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void perf_data__close_dir(struct perf_data *data)
3535
int perf_data__create_dir(struct perf_data *data, int nr)
3636
{
3737
struct perf_data_file *files = NULL;
38-
int i, ret = -1;
38+
int i, ret;
3939

4040
if (WARN_ON(!data->is_dir))
4141
return -EINVAL;
@@ -51,7 +51,8 @@ int perf_data__create_dir(struct perf_data *data, int nr)
5151
for (i = 0; i < nr; i++) {
5252
struct perf_data_file *file = &files[i];
5353

54-
if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0)
54+
ret = asprintf(&file->path, "%s/data.%d", data->path, i);
55+
if (ret < 0)
5556
goto out_err;
5657

5758
ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);

0 commit comments

Comments
 (0)