* [PATCH 1/8] perf c2c: Fix error return code in perf_c2c__report
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 2/8] perf lock: Fix error return code in __cmd_contention Shang XiaoJing
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
As the return error code of perf_c2c__report may has been assigned in
front, set the error code to -EINVAL or the specific error code of the
function.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-c2c.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 12f272811487..1fe5650d9b51 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -3110,6 +3110,8 @@ static int perf_c2c__report(int argc, const char **argv)
if (err)
goto out_mem2node;
+ err = -EINVAL;
+
if (symbol__init(&session->header.env) < 0)
goto out_mem2node;
@@ -3182,7 +3184,8 @@ static int perf_c2c__report(int argc, const char **argv)
ui_progress__finish();
- if (ui_quirks()) {
+ err = ui_quirks();
+ if (err) {
pr_err("failed to setup UI\n");
goto out_mem2node;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/8] perf lock: Fix error return code in __cmd_contention
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
2022-09-16 2:56 ` [PATCH 1/8] perf c2c: Fix error return code in perf_c2c__report Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 3/8] perf probe: Fix error return code in perf_del_probe_events Shang XiaoJing
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
As the return error code in __cmd_contention may has been assigned when
use_bpf is true, set the error code to -EINVAL or the specific error code
of the function.
BTW, the error code of add_output_field is also changed to ensure
setup_output_field can return specific error code instead of -1.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-lock.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 44a47648b7fe..c11ee901c238 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -335,7 +335,7 @@ static int add_output_field(bool contention, char *name)
}
pr_err("Unknown output field: %s\n", name);
- return -1;
+ return -EINVAL;
}
static int setup_output_field(bool contention, const char *str)
@@ -1626,6 +1626,7 @@ static int __cmd_contention(int argc, const char **argv)
if (lock_contention_prepare(&con) < 0) {
pr_err("lock contention BPF setup failed\n");
+ err = -EINVAL;
goto out_delete;
}
} else {
@@ -1645,11 +1646,14 @@ static int __cmd_contention(int argc, const char **argv)
}
}
- if (setup_output_field(true, output_fields))
+ err = setup_output_field(true, output_fields);
+ if (err < 0)
goto out_delete;
- if (select_key(true))
+ if (select_key(true)) {
+ err = -EINVAL;
goto out_delete;
+ }
if (show_thread_stats)
aggr_mode = LOCK_AGGR_TASK;
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/8] perf probe: Fix error return code in perf_del_probe_events
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
2022-09-16 2:56 ` [PATCH 1/8] perf c2c: Fix error return code in perf_c2c__report Shang XiaoJing
2022-09-16 2:56 ` [PATCH 2/8] perf lock: Fix error return code in __cmd_contention Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 4/8] perf record: Fix error return code in cmd_record Shang XiaoJing
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Set the error return code in perf_del_probe_events as ret2 when the
correct error code is recorded in ret2.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-probe.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index f62298f5db3b..b1a7876d9031 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -465,10 +465,14 @@ static int perf_del_probe_events(struct strfilter *filter)
pr_info("Removed event: %s\n", ent->s);
ret2 = probe_file__del_strlist(ufd, ulist);
- if (ret2 < 0)
+ if (ret2 < 0) {
+ ret = ret2;
goto error;
- } else if (ret2 == -ENOMEM)
+ }
+ } else if (ret2 == -ENOMEM) {
+ ret = ret2;
goto error;
+ }
if (ret == -ENOENT && ret2 == -ENOENT)
pr_warning("\"%s\" does not hit any event.\n", str);
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/8] perf record: Fix error return code in cmd_record
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
` (2 preceding siblings ...)
2022-09-16 2:56 ` [PATCH 3/8] perf probe: Fix error return code in perf_del_probe_events Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 5/8] perf report: Fix error return code in cmd_report Shang XiaoJing
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Set untimely updated error return code in cmd_record as -EINVAL when
there encounters the error.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-record.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9df77b81a3bb..b18692a4d776 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -3997,10 +3997,12 @@ int cmd_record(int argc, const char **argv)
if (record__threads_enabled(rec)) {
if (rec->opts.affinity != PERF_AFFINITY_SYS) {
pr_err("--affinity option is mutually exclusive to parallel streaming mode.\n");
+ err = -EINVAL;
goto out_opts;
}
if (record__aio_enabled(rec)) {
pr_err("Asynchronous streaming mode (--aio) is mutually exclusive to parallel streaming mode.\n");
+ err = -EINVAL;
goto out_opts;
}
}
@@ -4143,6 +4145,7 @@ int cmd_record(int argc, const char **argv)
if (evlist__fix_hybrid_cpus(rec->evlist, rec->opts.target.cpu_list)) {
pr_err("failed to use cpu list %s\n",
rec->opts.target.cpu_list);
+ err = -EINVAL;
goto out;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/8] perf report: Fix error return code in cmd_report
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
` (3 preceding siblings ...)
2022-09-16 2:56 ` [PATCH 4/8] perf record: Fix error return code in cmd_record Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 6/8] perf sched: Fix error return code in perf_sched__timehist Shang XiaoJing
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Reset the error return code in cmd_report as -EINVAL after assigned by
evswitch__init. Set the error code as -EINVAL when symbol__init failed.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-report.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 8361890176c2..094256bde981 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1481,6 +1481,8 @@ int cmd_report(int argc, const char **argv)
goto error;
}
+ ret = -EINVAL;
+
if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch)
has_br_stack = true;
@@ -1644,8 +1646,10 @@ int cmd_report(int argc, const char **argv)
annotation_config__init(&report.annotation_opts);
}
- if (symbol__init(&session->header.env) < 0)
+ if (symbol__init(&session->header.env) < 0) {
+ ret = -EINVAL;
goto error;
+ }
if (report.time_str) {
ret = perf_time__parse_for_ranges(report.time_str, session,
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/8] perf sched: Fix error return code in perf_sched__timehist
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
` (4 preceding siblings ...)
2022-09-16 2:56 ` [PATCH 5/8] perf report: Fix error return code in cmd_report Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 7/8] perf stat: Fix error return code in cmd_stat Shang XiaoJing
2022-09-16 2:56 ` [PATCH 8/8] perf trace: Fix error return code in trace__replay and cmd_trace Shang XiaoJing
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Reset the error return code in perf_sched__timehist to -1 after assigned
by perf_session__cpu_bitmap, to ensure the following checks wont return
the error code of perf_session__cpu_bitmap.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-sched.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index a92610eac4bf..4b9d2bc916b3 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -3027,6 +3027,7 @@ static int perf_sched__timehist(struct perf_sched *sched)
err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
if (err < 0)
goto out;
+ err = -1;
}
evlist = session->evlist;
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/8] perf stat: Fix error return code in cmd_stat
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
` (5 preceding siblings ...)
2022-09-16 2:56 ` [PATCH 6/8] perf sched: Fix error return code in perf_sched__timehist Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
2022-09-16 2:56 ` [PATCH 8/8] perf trace: Fix error return code in trace__replay and cmd_trace Shang XiaoJing
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Reset the error return value in cmd_stat as -EINVAL after assigned, and
use the specific error code of evlist__expand_cgroup, for correct error
code.
BTW, change the default error code of evlist__expand_cgroup to ensure it
can return specific value instead of -1.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-stat.c | 9 +++++++--
tools/perf/util/cgroup.c | 2 +-
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 54cd29d07ca8..559ffa107218 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2427,6 +2427,7 @@ int cmd_stat(int argc, const char **argv)
iostat_list(evsel_list, &stat_config);
if (iostat_mode == IOSTAT_RUN && !target__has_cpu(&target))
target.system_wide = true;
+ status = -EINVAL;
}
if (add_default_attributes())
@@ -2440,12 +2441,16 @@ int cmd_stat(int argc, const char **argv)
goto out;
}
- if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list,
- &stat_config.metric_events, true) < 0) {
+ status = evlist__expand_cgroup(evsel_list,
+ stat_config.cgroup_list,
+ &stat_config.metric_events,
+ true);
+ if (status < 0) {
parse_options_usage(stat_usage, stat_options,
"for-each-cgroup", 0);
goto out;
}
+ status = -EINVAL;
}
if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide))
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index e99b41f9be45..e3c6fc54dde5 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -400,7 +400,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str,
struct rblist orig_metric_events;
struct cgroup *cgrp = NULL;
struct cgroup_name *cn;
- int ret = -1;
+ int ret = -EINVAL;
int prefix_len;
if (evlist->core.nr_entries == 0) {
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/8] perf trace: Fix error return code in trace__replay and cmd_trace
2022-09-16 2:56 [PATCH 0/8] perf: Fix error return code Shang XiaoJing
` (6 preceding siblings ...)
2022-09-16 2:56 ` [PATCH 7/8] perf stat: Fix error return code in cmd_stat Shang XiaoJing
@ 2022-09-16 2:56 ` Shang XiaoJing
7 siblings, 0 replies; 9+ messages in thread
From: Shang XiaoJing @ 2022-09-16 2:56 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-perf-users
Cc: shangxiaojing
Reset the error return code in trace__replay to -1 after it is assigned
by others, and use PTR_ERR(evsel) as the error code in cmd_trace for more
accurate.
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
tools/perf/builtin-trace.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 3ecc31375f90..57a6ba158bf1 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -4277,6 +4277,8 @@ static int trace__replay(struct trace *trace)
if (err)
goto out;
+ err = -1;
+
evsel = evlist__find_tracepoint_by_name(session->evlist, "raw_syscalls:sys_enter");
trace->syscalls.events.sys_enter = evsel;
/* older kernels have syscalls tp versus raw_syscalls */
@@ -4972,9 +4974,12 @@ int cmd_trace(int argc, const char **argv)
if (IS_ERR(evsel)) {
bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf));
pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf);
+ err = PTR_ERR(evsel);
goto out;
}
+ err = -1;
+
if (evsel) {
trace.syscalls.events.augmented = evsel;
--
2.17.1
^ permalink raw reply related [flat|nested] 9+ messages in thread