perf: Fix error return code
cover perf: Fix error return code
Set the error return code that has been assigned by previous function to the default value, which may caused by the patches insert function that assign to the error code and overwrites the default one.
Shang XiaoJing (8):
perf c2c: Fix error return code in perf_c2c__report perf lock: Fix error return code in __cmd_contention perf probe: Fix error return code in perf_del_probe_events perf record: Fix error return code in cmd_record
perf report: Fix error return code in cmd_report
perf sched: Fix error return code in perf_sched__timehist perf stat: Fix error return code in cmd_stat
perf trace: Fix error return code in trace__replay and cmd_trace
tools/perf/builtin-c2c.c | 5 ++++- tools/perf/builtin-lock.c | 10 +++++++--- tools/perf/builtin-probe.c | 8 ++++++-- tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-report.c | 6 +++++- tools/perf/builtin-sched.c | 1 + tools/perf/builtin-stat.c | 9 +++++++-- tools/perf/builtin-trace.c | 5 +++++ tools/perf/util/cgroup.c | 2 +- 9 files changed, 39 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/8 perf c2c: Fix error return code in perf_c2c__report
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.
--- tools/perf/builtin-c2c.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-c2c.c +4 -1
@@ -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; }
Signature · 1 line
2.17.1
PATCH 2/8 perf lock: Fix error return code in __cmd_contention
In reply to Shang XiaoJingAs 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.
--- tools/perf/builtin-lock.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/builtin-lock.c +7 -3
@@ -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 ;
Signature · 1 line
2.17.1
PATCH 3/8 perf probe: Fix error return code in perf_del_probe_events
In reply to Shang XiaoJingSet the error return code in perf_del_probe_events as ret2 when the correct error code is recorded in ret2.
--- tools/perf/builtin-probe.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +6 -2
@@ -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);
Signature · 1 line
2.17.1
PATCH 4/8 perf record: Fix error return code in cmd_record
In reply to Shang XiaoJingSet untimely updated error return code in cmd_record as -EINVAL when there encounters the error.
--- tools/perf/builtin-record.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/builtin-record.c +3 -0
@@ -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; }
Signature · 1 line
2.17.1
PATCH 5/8 perf report: Fix error return code in cmd_report
In reply to Shang XiaoJingReset the error return code in cmd_report as -EINVAL after assigned by evswitch__init. Set the error code as -EINVAL when symbol__init failed.
--- tools/perf/builtin-report.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +5 -1
@@ -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,
Signature · 1 line
2.17.1
PATCH 6/8 perf sched: Fix error return code in perf_sched__timehist
In reply to Shang XiaoJingReset 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.
--- tools/perf/builtin-sched.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-sched.c +1 -0
@@ -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;
Signature · 1 line
2.17.1
PATCH 7/8 perf stat: Fix error return code in cmd_stat
In reply to Shang XiaoJingReset 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.
--- tools/perf/builtin-stat.c | 9 +++++++-- tools/perf/util/cgroup.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/builtin-stat.c +7 -2
@@ -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))
tools/perf/util/cgroup.c +1 -1
@@ -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 ) {
Signature · 1 line
2.17.1
PATCH 8/8 perf trace: Fix error return code in trace__replay and cmd_trace
In reply to Shang XiaoJingReset 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.
--- tools/perf/builtin-trace.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/builtin-trace.c +5 -0
@@ -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;
Signature · 1 line
2.17.1