diff options
author | Hisao Tanabe <[email protected]> | 2018-08-25 00:45:56 +0900 |
---|---|---|
committer | Arnaldo Carvalho de Melo <[email protected]> | 2018-08-30 14:49:25 -0300 |
commit | fd8d2702791a970c751f8b526a17d8e725a05b46 (patch) | |
tree | 2f0b990e3a6909a7185ae5d80274af542409d642 | |
parent | 5ab1de932e2923f490645ad017a689c5b58dc433 (diff) |
perf evsel: Fix potential null pointer dereference in perf_evsel__new_idx()
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 <[email protected]>
Acked-by: Namhyung Kim <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Wang Nan <[email protected]>
Fixes: 03e0a7df3efd ("perf tools: Introduce bpf-output event")
LPU-Reference: [email protected]
Link: https://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r-- | tools/perf/util/evsel.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index c980bbff6353..1a61628a1c12 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -251,8 +251,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 | |