diff options
author | Leo Yan <leo.yan@linaro.org> | 2019-07-08 10:39:34 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-07-09 09:13:27 -0400 |
commit | ceb75476db1617a88cc29b09839acacb69aa076e (patch) | |
tree | bd147ee913ac5a3b00e47d8533b51805763dc505 | |
parent | 0702f23c983b8a921853c33a9f59b9cf0975d36e (diff) |
perf hists browser: Fix potential NULL pointer dereference found by the smatch tool
Based on the following report from Smatch, fix the potential
NULL pointer dereference check.
tools/perf/ui/browsers/hists.c:641
hist_browser__run() error: we previously assumed 'hbt' could be
null (see line 625)
tools/perf/ui/browsers/hists.c:3088
perf_evsel__hists_browse() error: we previously assumed
'browser->he_selection' could be null (see line 2902)
tools/perf/ui/browsers/hists.c:3272
perf_evsel_menu__run() error: we previously assumed 'hbt' could be
null (see line 3260)
This patch firstly validating the pointers before access them, so can
fix potential NULL pointer dereference.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/20190708143937.7722-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 85581cfb9112..a94eb0755e8b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -639,7 +639,11 @@ int hist_browser__run(struct hist_browser *browser, const char *help, | |||
639 | switch (key) { | 639 | switch (key) { |
640 | case K_TIMER: { | 640 | case K_TIMER: { |
641 | u64 nr_entries; | 641 | u64 nr_entries; |
642 | hbt->timer(hbt->arg); | 642 | |
643 | WARN_ON_ONCE(!hbt); | ||
644 | |||
645 | if (hbt) | ||
646 | hbt->timer(hbt->arg); | ||
643 | 647 | ||
644 | if (hist_browser__has_filter(browser) || | 648 | if (hist_browser__has_filter(browser) || |
645 | symbol_conf.report_hierarchy) | 649 | symbol_conf.report_hierarchy) |
@@ -2821,7 +2825,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
2821 | { | 2825 | { |
2822 | struct hists *hists = evsel__hists(evsel); | 2826 | struct hists *hists = evsel__hists(evsel); |
2823 | struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); | 2827 | struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); |
2824 | struct branch_info *bi; | 2828 | struct branch_info *bi = NULL; |
2825 | #define MAX_OPTIONS 16 | 2829 | #define MAX_OPTIONS 16 |
2826 | char *options[MAX_OPTIONS]; | 2830 | char *options[MAX_OPTIONS]; |
2827 | struct popup_action actions[MAX_OPTIONS]; | 2831 | struct popup_action actions[MAX_OPTIONS]; |
@@ -3087,7 +3091,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
3087 | goto skip_annotation; | 3091 | goto skip_annotation; |
3088 | 3092 | ||
3089 | if (sort__mode == SORT_MODE__BRANCH) { | 3093 | if (sort__mode == SORT_MODE__BRANCH) { |
3090 | bi = browser->he_selection->branch_info; | 3094 | |
3095 | if (browser->he_selection) | ||
3096 | bi = browser->he_selection->branch_info; | ||
3091 | 3097 | ||
3092 | if (bi == NULL) | 3098 | if (bi == NULL) |
3093 | goto skip_annotation; | 3099 | goto skip_annotation; |
@@ -3271,7 +3277,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, | |||
3271 | 3277 | ||
3272 | switch (key) { | 3278 | switch (key) { |
3273 | case K_TIMER: | 3279 | case K_TIMER: |
3274 | hbt->timer(hbt->arg); | 3280 | if (hbt) |
3281 | hbt->timer(hbt->arg); | ||
3275 | 3282 | ||
3276 | if (!menu->lost_events_warned && | 3283 | if (!menu->lost_events_warned && |
3277 | menu->lost_events && | 3284 | menu->lost_events && |