提交 946ae1d4 编写于 作者: W Wang Nan 提交者: Arnaldo Carvalho de Melo

perf evlist: Fix alloc_mmap() failure path

If zalloc fail, setting evlist->mmap[i].fd is unsafe and
perf_evlist__alloc_mmap() should bail out right after that.
Signed-off-by: NWang Nan <wangnan0@huawei.com>
Acked-by: NMasami Hiramatsu <mhiramat@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Fixes: d4c6fb36 ("perf evsel: Record fd into perf_mmap")
Link: http://lkml.kernel.org/r/1464699975-230440-1-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 90525176
...@@ -946,9 +946,12 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) ...@@ -946,9 +946,12 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
if (cpu_map__empty(evlist->cpus)) if (cpu_map__empty(evlist->cpus))
evlist->nr_mmaps = thread_map__nr(evlist->threads); evlist->nr_mmaps = thread_map__nr(evlist->threads);
evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap)); evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
if (!evlist->mmap)
return -ENOMEM;
for (i = 0; i < evlist->nr_mmaps; i++) for (i = 0; i < evlist->nr_mmaps; i++)
evlist->mmap[i].fd = -1; evlist->mmap[i].fd = -1;
return evlist->mmap != NULL ? 0 : -ENOMEM; return 0;
} }
struct mmap_params { struct mmap_params {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册