Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf top: Fix error code in cmd_top()

There are three error paths which return success:

1. Propagate the errno from evlist__create_maps() if it failed.

2. Return -EINVAL if top.sb_evlist is NULL.

3. Return -EINVAL if evlist__add_bpf_sb_event() failed.

Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220922141438.22487-4-shangxiaojing@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Shang XiaoJing and committed by
Arnaldo Carvalho de Melo
dc64641c cdd3b15d

+3
+3
tools/perf/builtin-top.c
··· 1707 1707 if (evlist__create_maps(top.evlist, target) < 0) { 1708 1708 ui__error("Couldn't create thread/CPU maps: %s\n", 1709 1709 errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf))); 1710 + status = -errno; 1710 1711 goto out_delete_evlist; 1711 1712 } 1712 1713 ··· 1760 1759 1761 1760 if (top.sb_evlist == NULL) { 1762 1761 pr_err("Couldn't create side band evlist.\n."); 1762 + status = -EINVAL; 1763 1763 goto out_delete_evlist; 1764 1764 } 1765 1765 1766 1766 if (evlist__add_bpf_sb_event(top.sb_evlist, &perf_env)) { 1767 1767 pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n."); 1768 + status = -EINVAL; 1768 1769 goto out_delete_evlist; 1769 1770 } 1770 1771 }