Skip to content

Commit 9d7bc32

Browse files
xtanabegregkh
authored andcommitted
perf evsel: Fix potential null pointer dereference in perf_evsel__new_idx()
[ Upstream commit fd8d270 ] If evsel is NULL, we should return NULL to avoid a NULL pointer dereference a bit later in the code. Signed-off-by: Hisao Tanabe <xtanabe@gmail.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Wang Nan <wangnan0@huawei.com> Fixes: 03e0a7d ("perf tools: Introduce bpf-output event") LPU-Reference: 20180824154556.23428-1-xtanabe@gmail.com Link: https://lkml.kernel.org/n/tip-e5plzjhx6595a5yjaf22jss3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8b98b7e commit 9d7bc32

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tools/perf/util/evsel.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
259259
{
260260
struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
261261

262-
if (evsel != NULL)
263-
perf_evsel__init(evsel, attr, idx);
262+
if (!evsel)
263+
return NULL;
264+
perf_evsel__init(evsel, attr, idx);
264265

265266
if (perf_evsel__is_bpf_output(evsel)) {
266267
evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |

0 commit comments

Comments
 (0)