From: Jiri Olsa Date: Sun, 10 Jul 2016 11:07:56 +0000 (+0200) Subject: perf python: Fix pyrf_evlist__read_on_cpu event consuming X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e8968e654191390a1300f0847250353a1c9da30d;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git perf python: Fix pyrf_evlist__read_on_cpu event consuming We can't consume the event before parsing it. Under heavy load we could get caught by kernel writer overwriting the event we're trying to parse. Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1468148882-10362-5-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index d0c1267741ee..c68ef0319114 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -865,12 +865,14 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, PyObject *pyevent = pyrf_event__new(event); struct pyrf_event *pevent = (struct pyrf_event *)pyevent; - perf_evlist__mmap_consume(evlist, cpu); - if (pyevent == NULL) return PyErr_NoMemory(); err = perf_evlist__parse_sample(evlist, event, &pevent->sample); + + /* Consume the even only after we parsed it out. */ + perf_evlist__mmap_consume(evlist, cpu); + if (err) return PyErr_Format(PyExc_OSError, "perf: can't parse sample, err=%d", err);