Commit 6040d231 authored by Hisao Tanabe's avatar Hisao Tanabe Committed by Greg Kroah-Hartman

perf evsel: Fix potential null pointer dereference in perf_evsel__new_idx()

[ Upstream commit fd8d2702791a970c751f8b526a17d8e725a05b46 ]

If evsel is NULL, we should return NULL to avoid a NULL pointer
dereference a bit later in the code.
Signed-off-by: default avatarHisao Tanabe <>
Acked-by: default avatarNamhyung Kim <>
Cc: Jiri Olsa <>
Cc: Wang Nan <>
Fixes: 03e0a7df ("perf tools: Introduce bpf-output event")
Link: default avatarArnaldo Carvalho de Melo <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent a80e03b6
......@@ -241,8 +241,9 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
if (evsel != NULL)
perf_evsel__init(evsel, attr, idx);
if (!evsel)
return NULL;
perf_evsel__init(evsel, attr, idx);
if (perf_evsel__is_bpf_output(evsel)) {
evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
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