Skip to content

Commit

Permalink
perf map: Fix error return code in maps__clone()
Browse files Browse the repository at this point in the history
[ Upstream commit c6f8714 ]

Although 'err' has been initialized to -ENOMEM, but it will be reassigned
by the "err = unwind__prepare_access(...)" statement in the for loop. So
that, the value of 'err' is unknown when map__clone() failed.

Fixes: 6c50258 ("perf unwind: Call unwind__prepare_access for forked thread")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen 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>
Cc: zhen lei <thunder.leizhen@huawei.com>
Link: http://lore.kernel.org/lkml/20210415092744.3793-1-thunder.leizhen@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Zhen Lei authored and gregkh committed Apr 28, 2021
1 parent 508a1c4 commit 4818936
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/perf/util/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,18 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
int maps__clone(struct thread *thread, struct maps *parent)
{
struct maps *maps = thread->maps;
int err = -ENOMEM;
int err;
struct map *map;

down_read(&parent->lock);

maps__for_each_entry(parent, map) {
struct map *new = map__clone(map);
if (new == NULL)

if (new == NULL) {
err = -ENOMEM;
goto out_unlock;
}

err = unwind__prepare_access(maps, new, NULL);
if (err)
Expand Down

0 comments on commit 4818936

Please sign in to comment.