Skip to content

Commit c45628b

Browse files
WangNan0acmel
authored andcommitted
perf record: Robustify perf_event__synth_time_conv()
It is possible that all events in an evlist are overwritable. perf_event__synth_time_conv() should not crash in this case. record__pick_pc() is used to check avaliability. Signed-off-by: Wang Nan <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: He Kuang <[email protected]> [ Split from a larger patch ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 792d48b commit c45628b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tools/perf/arch/x86/util/tsc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
6262
struct perf_tsc_conversion tc;
6363
int err;
6464

65+
if (!pc)
66+
return 0;
6567
err = perf_read_tsc_conversion(pc, &tc);
6668
if (err == -EOPNOTSUPP)
6769
return 0;

tools/perf/builtin-record.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,13 @@ perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused
655655
return 0;
656656
}
657657

658+
static const struct perf_event_mmap_page *record__pick_pc(struct record *rec)
659+
{
660+
if (rec->evlist && rec->evlist->mmap && rec->evlist->mmap[0].base)
661+
return rec->evlist->mmap[0].base;
662+
return NULL;
663+
}
664+
658665
static int record__synthesize(struct record *rec)
659666
{
660667
struct perf_session *session = rec->session;
@@ -692,7 +699,7 @@ static int record__synthesize(struct record *rec)
692699
}
693700
}
694701

695-
err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
702+
err = perf_event__synth_time_conv(record__pick_pc(rec), tool,
696703
process_synthesized_event, machine);
697704
if (err)
698705
goto out;

0 commit comments

Comments
 (0)