OSDN Git Service

perf top: Fix error code in cmd_top()
authorShang XiaoJing <shangxiaojing@huawei.com>
Thu, 22 Sep 2022 14:14:37 +0000 (22:14 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Oct 2022 11:55:22 +0000 (08:55 -0300)
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>
tools/perf/builtin-top.c

index e89208b..4b3ff76 100644 (file)
@@ -1707,6 +1707,7 @@ int cmd_top(int argc, const char **argv)
        if (evlist__create_maps(top.evlist, target) < 0) {
                ui__error("Couldn't create thread/CPU maps: %s\n",
                          errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
+               status = -errno;
                goto out_delete_evlist;
        }
 
@@ -1759,11 +1760,13 @@ int cmd_top(int argc, const char **argv)
 
                if (top.sb_evlist == NULL) {
                        pr_err("Couldn't create side band evlist.\n.");
+                       status = -EINVAL;
                        goto out_delete_evlist;
                }
 
                if (evlist__add_bpf_sb_event(top.sb_evlist, &perf_env)) {
                        pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
+                       status = -EINVAL;
                        goto out_delete_evlist;
                }
        }