Commit d61cbb85 authored by Wei Li's avatar Wei Li Committed by Arnaldo Carvalho de Melo

perf report TUI: Fix segmentation fault in perf_evsel__hists_browse()

The segmentation fault can be reproduced as following steps:

1) Executing perf report in tui.

2) Typing '/xxxxx' to filter the symbol to get nothing matched.

3) Pressing enter with no entry selected.

Then it will report a segmentation fault.

It is caused by the lack of check of browser->he_selection when
accessing it's member res_samples in perf_evsel__hists_browse().

These processes are meaningful for specified samples, so we can skip
these when nothing is selected.

Fixes: 4968ac8f ("perf report: Implement browsing of individual samples")
Signed-off-by: default avatarWei Li <liwei391@huawei.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Link: http://lore.kernel.org/lkml/20200612094322.39565-1-liwei391@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2160d6c8
...@@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser ...@@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser
return browser->he_selection->thread; return browser->he_selection->thread;
} }
static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser)
{
return browser->he_selection ? browser->he_selection->res_samples : NULL;
}
/* Check whether the browser is for 'top' or 'report' */ /* Check whether the browser is for 'top' or 'report' */
static inline bool is_report_browser(void *timer) static inline bool is_report_browser(void *timer)
{ {
...@@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events, ...@@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
&options[nr_options], NULL, NULL, evsel); &options[nr_options], NULL, NULL, evsel);
nr_options += add_res_sample_opt(browser, &actions[nr_options], nr_options += add_res_sample_opt(browser, &actions[nr_options],
&options[nr_options], &options[nr_options],
hist_browser__selected_entry(browser)->res_samples, hist_browser__selected_res_sample(browser),
evsel, A_NORMAL); evsel, A_NORMAL);
nr_options += add_res_sample_opt(browser, &actions[nr_options], nr_options += add_res_sample_opt(browser, &actions[nr_options],
&options[nr_options], &options[nr_options],
hist_browser__selected_entry(browser)->res_samples, hist_browser__selected_res_sample(browser),
evsel, A_ASM); evsel, A_ASM);
nr_options += add_res_sample_opt(browser, &actions[nr_options], nr_options += add_res_sample_opt(browser, &actions[nr_options],
&options[nr_options], &options[nr_options],
hist_browser__selected_entry(browser)->res_samples, hist_browser__selected_res_sample(browser),
evsel, A_SOURCE); evsel, A_SOURCE);
nr_options += add_switch_opt(browser, &actions[nr_options], nr_options += add_switch_opt(browser, &actions[nr_options],
&options[nr_options]); &options[nr_options]);
skip_scripting: skip_scripting:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment