linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shang XiaoJing <shangxiaojing@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@kernel.org>, <namhyung@kernel.org>,
	<linux-perf-users@vger.kernel.org>
Cc: <shangxiaojing@huawei.com>
Subject: [PATCH 7/8] perf stat: Fix error return code in cmd_stat
Date: Fri, 16 Sep 2022 10:56:26 +0800	[thread overview]
Message-ID: <20220916025627.13967-8-shangxiaojing@huawei.com> (raw)
In-Reply-To: <20220916025627.13967-1-shangxiaojing@huawei.com>

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


  parent reply	other threads:[~2022-09-16  2:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` [PATCH 3/8] perf probe: Fix error return code in perf_del_probe_events Shang XiaoJing
2022-09-16  2:56 ` [PATCH 4/8] perf record: Fix error return code in cmd_record Shang XiaoJing
2022-09-16  2:56 ` [PATCH 5/8] perf report: Fix error return code in cmd_report Shang XiaoJing
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 [this message]
2022-09-16  2:56 ` [PATCH 8/8] perf trace: Fix error return code in trace__replay and cmd_trace Shang XiaoJing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220916025627.13967-8-shangxiaojing@huawei.com \
    --to=shangxiaojing@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).