[tip:perf/urgent] perf intel-pt: Fix divide by zero when TSC is not available

From: tip-bot for Adrian Hunter
Date: Sat Mar 09 2019 - 14:50:53 EST


Commit-ID: 076333870c2f5bdd9b6d31e7ca1909cf0c84cbfa
Gitweb: https://git.kernel.org/tip/076333870c2f5bdd9b6d31e7ca1909cf0c84cbfa
Author: Adrian Hunter <adrian.hunter@xxxxxxxxx>
AuthorDate: Fri, 1 Mar 2019 12:35:36 +0200
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Fri, 1 Mar 2019 14:48:30 -0300

perf intel-pt: Fix divide by zero when TSC is not available

When TSC is not available, "timeless" decoding is used but a divide by
zero occurs if perf_time_to_tsc() is called.

Ensure the divisor is not zero.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx # v4.9+
Link: https://lkml.kernel.org/n/tip-1i4j0wqoc8vlbkcizqqxpsf4@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/intel-pt.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 3b497bab4324..6d288237887b 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2531,6 +2531,8 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
}

pt->timeless_decoding = intel_pt_timeless_decoding(pt);
+ if (pt->timeless_decoding && !pt->tc.time_mult)
+ pt->tc.time_mult = 1;
pt->have_tsc = intel_pt_have_tsc(pt);
pt->sampling_mode = false;
pt->est_tsc = !pt->timeless_decoding;