diff options
author | Mamatha Inamdar <mamatha4@linux.vnet.ibm.com> | 2019-08-22 03:20:49 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-09-20 14:58:11 -0400 |
commit | 6ef81c55a2b6584cb642917f5fdf3632ef44b670 (patch) | |
tree | 524c57e82fa0f5b59b5bec95b65c3066015fbe02 | |
parent | 9e6124d9d635957b56717f85219a88701617253f (diff) |
perf session: Return error code for perf_session__new() function on failure
This patch is to return error code of perf_new_session function on
failure instead of NULL.
Test Results:
Before Fix:
$ perf c2c report -input
failed to open nput: No such file or directory
$ echo $?
0
$
After Fix:
$ perf c2c report -input
failed to open nput: No such file or directory
$ echo $?
254
$
Committer notes:
Fix 'perf tests topology' case, where we use that TEST_ASSERT_VAL(...,
session), i.e. we need to pass zero in case of failure, which was the
case before when NULL was returned by perf_session__new() for failure,
but now we need to negate the result of IS_ERR(session) to respect that
TEST_ASSERT_VAL) expectation of zero meaning failure.
Reported-by: Nageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Signed-off-by: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Nageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shawn Landden <shawn@git.icu>
Cc: Song Liu <songliubraving@fb.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Link: http://lore.kernel.org/lkml/20190822071223.17892.45782.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-annotate.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-buildid-cache.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-buildid-list.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-c2c.c | 6 | ||||
-rw-r--r-- | tools/perf/builtin-diff.c | 9 | ||||
-rw-r--r-- | tools/perf/builtin-evlist.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-inject.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-kmem.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-kvm.c | 9 | ||||
-rw-r--r-- | tools/perf/builtin-lock.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-mem.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 11 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 9 | ||||
-rw-r--r-- | tools/perf/builtin-stat.c | 11 | ||||
-rw-r--r-- | tools/perf/builtin-timechart.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-top.c | 5 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/topology.c | 5 | ||||
-rw-r--r-- | tools/perf/util/data-convert-bt.c | 5 | ||||
-rw-r--r-- | tools/perf/util/session.c | 15 |
22 files changed, 86 insertions, 57 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 553c651fa0a2..8db8fc9bddef 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <dlfcn.h> | 40 | #include <dlfcn.h> |
41 | #include <errno.h> | 41 | #include <errno.h> |
42 | #include <linux/bitmap.h> | 42 | #include <linux/bitmap.h> |
43 | #include <linux/err.h> | ||
43 | 44 | ||
44 | struct perf_annotate { | 45 | struct perf_annotate { |
45 | struct perf_tool tool; | 46 | struct perf_tool tool; |
@@ -584,8 +585,8 @@ int cmd_annotate(int argc, const char **argv) | |||
584 | data.path = input_name; | 585 | data.path = input_name; |
585 | 586 | ||
586 | annotate.session = perf_session__new(&data, false, &annotate.tool); | 587 | annotate.session = perf_session__new(&data, false, &annotate.tool); |
587 | if (annotate.session == NULL) | 588 | if (IS_ERR(annotate.session)) |
588 | return -1; | 589 | return PTR_ERR(annotate.session); |
589 | 590 | ||
590 | annotate.has_br_stack = perf_header__has_feat(&annotate.session->header, | 591 | annotate.has_br_stack = perf_header__has_feat(&annotate.session->header, |
591 | HEADER_BRANCH_STACK); | 592 | HEADER_BRANCH_STACK); |
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 1a69eb565dc0..39efa51d7fb3 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "util/util.h" | 28 | #include "util/util.h" |
29 | #include "util/probe-file.h" | 29 | #include "util/probe-file.h" |
30 | #include <linux/string.h> | 30 | #include <linux/string.h> |
31 | #include <linux/err.h> | ||
31 | 32 | ||
32 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) | 33 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) |
33 | { | 34 | { |
@@ -422,8 +423,8 @@ int cmd_buildid_cache(int argc, const char **argv) | |||
422 | data.force = force; | 423 | data.force = force; |
423 | 424 | ||
424 | session = perf_session__new(&data, false, NULL); | 425 | session = perf_session__new(&data, false, NULL); |
425 | if (session == NULL) | 426 | if (IS_ERR(session)) |
426 | return -1; | 427 | return PTR_ERR(session); |
427 | } | 428 | } |
428 | 429 | ||
429 | if (symbol__init(session ? &session->header.env : NULL) < 0) | 430 | if (symbol__init(session ? &session->header.env : NULL) < 0) |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 5a0d8b378cb5..e3ef75583514 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include "util/symbol.h" | 18 | #include "util/symbol.h" |
19 | #include "util/data.h" | 19 | #include "util/data.h" |
20 | #include <errno.h> | 20 | #include <errno.h> |
21 | #include <linux/err.h> | ||
21 | 22 | ||
22 | static int sysfs__fprintf_build_id(FILE *fp) | 23 | static int sysfs__fprintf_build_id(FILE *fp) |
23 | { | 24 | { |
@@ -65,8 +66,8 @@ static int perf_session__list_build_ids(bool force, bool with_hits) | |||
65 | goto out; | 66 | goto out; |
66 | 67 | ||
67 | session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops); | 68 | session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops); |
68 | if (session == NULL) | 69 | if (IS_ERR(session)) |
69 | return -1; | 70 | return PTR_ERR(session); |
70 | 71 | ||
71 | /* | 72 | /* |
72 | * We take all buildids when the file contains AUX area tracing data | 73 | * We take all buildids when the file contains AUX area tracing data |
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 61aaacc2aedd..3542b6ab9813 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <errno.h> | 13 | #include <errno.h> |
14 | #include <inttypes.h> | 14 | #include <inttypes.h> |
15 | #include <linux/compiler.h> | 15 | #include <linux/compiler.h> |
16 | #include <linux/err.h> | ||
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/stringify.h> | 18 | #include <linux/stringify.h> |
18 | #include <linux/zalloc.h> | 19 | #include <linux/zalloc.h> |
@@ -2781,8 +2782,9 @@ static int perf_c2c__report(int argc, const char **argv) | |||
2781 | } | 2782 | } |
2782 | 2783 | ||
2783 | session = perf_session__new(&data, 0, &c2c.tool); | 2784 | session = perf_session__new(&data, 0, &c2c.tool); |
2784 | if (session == NULL) { | 2785 | if (IS_ERR(session)) { |
2785 | pr_debug("No memory for session\n"); | 2786 | err = PTR_ERR(session); |
2787 | pr_debug("Error creating perf session\n"); | ||
2786 | goto out; | 2788 | goto out; |
2787 | } | 2789 | } |
2788 | 2790 | ||
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 827e4800d862..c37a78677955 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "util/time-utils.h" | 23 | #include "util/time-utils.h" |
24 | #include "util/annotate.h" | 24 | #include "util/annotate.h" |
25 | #include "util/map.h" | 25 | #include "util/map.h" |
26 | #include <linux/err.h> | ||
26 | #include <linux/zalloc.h> | 27 | #include <linux/zalloc.h> |
27 | #include <subcmd/pager.h> | 28 | #include <subcmd/pager.h> |
28 | #include <subcmd/parse-options.h> | 29 | #include <subcmd/parse-options.h> |
@@ -1153,9 +1154,9 @@ static int check_file_brstack(void) | |||
1153 | 1154 | ||
1154 | data__for_each_file(i, d) { | 1155 | data__for_each_file(i, d) { |
1155 | d->session = perf_session__new(&d->data, false, &pdiff.tool); | 1156 | d->session = perf_session__new(&d->data, false, &pdiff.tool); |
1156 | if (!d->session) { | 1157 | if (IS_ERR(d->session)) { |
1157 | pr_err("Failed to open %s\n", d->data.path); | 1158 | pr_err("Failed to open %s\n", d->data.path); |
1158 | return -1; | 1159 | return PTR_ERR(d->session); |
1159 | } | 1160 | } |
1160 | 1161 | ||
1161 | has_br_stack = perf_header__has_feat(&d->session->header, | 1162 | has_br_stack = perf_header__has_feat(&d->session->header, |
@@ -1185,9 +1186,9 @@ static int __cmd_diff(void) | |||
1185 | 1186 | ||
1186 | data__for_each_file(i, d) { | 1187 | data__for_each_file(i, d) { |
1187 | d->session = perf_session__new(&d->data, false, &pdiff.tool); | 1188 | d->session = perf_session__new(&d->data, false, &pdiff.tool); |
1188 | if (!d->session) { | 1189 | if (IS_ERR(d->session)) { |
1190 | ret = PTR_ERR(d->session); | ||
1189 | pr_err("Failed to open %s\n", d->data.path); | 1191 | pr_err("Failed to open %s\n", d->data.path); |
1190 | ret = -1; | ||
1191 | goto out_delete; | 1192 | goto out_delete; |
1192 | } | 1193 | } |
1193 | 1194 | ||
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index 294494e60e48..60509ce4dd28 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "util/session.h" | 15 | #include "util/session.h" |
16 | #include "util/data.h" | 16 | #include "util/data.h" |
17 | #include "util/debug.h" | 17 | #include "util/debug.h" |
18 | #include <linux/err.h> | ||
18 | 19 | ||
19 | static int __cmd_evlist(const char *file_name, struct perf_attr_details *details) | 20 | static int __cmd_evlist(const char *file_name, struct perf_attr_details *details) |
20 | { | 21 | { |
@@ -28,8 +29,8 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details | |||
28 | bool has_tracepoint = false; | 29 | bool has_tracepoint = false; |
29 | 30 | ||
30 | session = perf_session__new(&data, 0, NULL); | 31 | session = perf_session__new(&data, 0, NULL); |
31 | if (session == NULL) | 32 | if (IS_ERR(session)) |
32 | return -1; | 33 | return PTR_ERR(session); |
33 | 34 | ||
34 | evlist__for_each_entry(session->evlist, pos) { | 35 | evlist__for_each_entry(session->evlist, pos) { |
35 | perf_evsel__fprintf(pos, details, stdout); | 36 | perf_evsel__fprintf(pos, details, stdout); |
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 23a76cf3846f..372ecb3e2c06 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "util/symbol.h" | 23 | #include "util/symbol.h" |
24 | #include "util/synthetic-events.h" | 24 | #include "util/synthetic-events.h" |
25 | #include "util/thread.h" | 25 | #include "util/thread.h" |
26 | #include <linux/err.h> | ||
26 | 27 | ||
27 | #include <subcmd/parse-options.h> | 28 | #include <subcmd/parse-options.h> |
28 | 29 | ||
@@ -835,8 +836,8 @@ int cmd_inject(int argc, const char **argv) | |||
835 | 836 | ||
836 | data.path = inject.input_name; | 837 | data.path = inject.input_name; |
837 | inject.session = perf_session__new(&data, true, &inject.tool); | 838 | inject.session = perf_session__new(&data, true, &inject.tool); |
838 | if (inject.session == NULL) | 839 | if (IS_ERR(inject.session)) |
839 | return -1; | 840 | return PTR_ERR(inject.session); |
840 | 841 | ||
841 | if (zstd_init(&(inject.session->zstd_data), 0) < 0) | 842 | if (zstd_init(&(inject.session->zstd_data), 0) < 0) |
842 | pr_warning("Decompression initialization failed.\n"); | 843 | pr_warning("Decompression initialization failed.\n"); |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b5682beaad72..1e61e353f579 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "util/tool.h" | 14 | #include "util/tool.h" |
15 | #include "util/callchain.h" | 15 | #include "util/callchain.h" |
16 | #include "util/time-utils.h" | 16 | #include "util/time-utils.h" |
17 | #include <linux/err.h> | ||
17 | 18 | ||
18 | #include <subcmd/pager.h> | 19 | #include <subcmd/pager.h> |
19 | #include <subcmd/parse-options.h> | 20 | #include <subcmd/parse-options.h> |
@@ -1956,8 +1957,8 @@ int cmd_kmem(int argc, const char **argv) | |||
1956 | data.path = input_name; | 1957 | data.path = input_name; |
1957 | 1958 | ||
1958 | kmem_session = session = perf_session__new(&data, false, &perf_kmem); | 1959 | kmem_session = session = perf_session__new(&data, false, &perf_kmem); |
1959 | if (session == NULL) | 1960 | if (IS_ERR(session)) |
1960 | return -1; | 1961 | return PTR_ERR(session); |
1961 | 1962 | ||
1962 | ret = -1; | 1963 | ret = -1; |
1963 | 1964 | ||
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 6e3e36658900..c4b22e1b0a40 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <sys/stat.h> | 33 | #include <sys/stat.h> |
34 | #include <fcntl.h> | 34 | #include <fcntl.h> |
35 | 35 | ||
36 | #include <linux/err.h> | ||
36 | #include <linux/kernel.h> | 37 | #include <linux/kernel.h> |
37 | #include <linux/string.h> | 38 | #include <linux/string.h> |
38 | #include <linux/time64.h> | 39 | #include <linux/time64.h> |
@@ -1091,9 +1092,9 @@ static int read_events(struct perf_kvm_stat *kvm) | |||
1091 | 1092 | ||
1092 | kvm->tool = eops; | 1093 | kvm->tool = eops; |
1093 | kvm->session = perf_session__new(&file, false, &kvm->tool); | 1094 | kvm->session = perf_session__new(&file, false, &kvm->tool); |
1094 | if (!kvm->session) { | 1095 | if (IS_ERR(kvm->session)) { |
1095 | pr_err("Initializing perf session failed\n"); | 1096 | pr_err("Initializing perf session failed\n"); |
1096 | return -1; | 1097 | return PTR_ERR(kvm->session); |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | symbol__init(&kvm->session->header.env); | 1100 | symbol__init(&kvm->session->header.env); |
@@ -1446,8 +1447,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, | |||
1446 | * perf session | 1447 | * perf session |
1447 | */ | 1448 | */ |
1448 | kvm->session = perf_session__new(&data, false, &kvm->tool); | 1449 | kvm->session = perf_session__new(&data, false, &kvm->tool); |
1449 | if (kvm->session == NULL) { | 1450 | if (IS_ERR(kvm->session)) { |
1450 | err = -1; | 1451 | err = PTR_ERR(kvm->session); |
1451 | goto out; | 1452 | goto out; |
1452 | } | 1453 | } |
1453 | kvm->session->evlist = kvm->evlist; | 1454 | kvm->session->evlist = kvm->evlist; |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 4c2b7f437cdf..474dfd59d7eb 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/hash.h> | 30 | #include <linux/hash.h> |
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/zalloc.h> | 32 | #include <linux/zalloc.h> |
33 | #include <linux/err.h> | ||
33 | 34 | ||
34 | static struct perf_session *session; | 35 | static struct perf_session *session; |
35 | 36 | ||
@@ -872,9 +873,9 @@ static int __cmd_report(bool display_info) | |||
872 | }; | 873 | }; |
873 | 874 | ||
874 | session = perf_session__new(&data, false, &eops); | 875 | session = perf_session__new(&data, false, &eops); |
875 | if (!session) { | 876 | if (IS_ERR(session)) { |
876 | pr_err("Initializing perf session failed\n"); | 877 | pr_err("Initializing perf session failed\n"); |
877 | return -1; | 878 | return PTR_ERR(session); |
878 | } | 879 | } |
879 | 880 | ||
880 | symbol__init(&session->header.env); | 881 | symbol__init(&session->header.env); |
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 27d2bde943a8..a13f5817d6fc 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "util/dso.h" | 17 | #include "util/dso.h" |
18 | #include "util/map.h" | 18 | #include "util/map.h" |
19 | #include "util/symbol.h" | 19 | #include "util/symbol.h" |
20 | #include <linux/err.h> | ||
20 | 21 | ||
21 | #define MEM_OPERATION_LOAD 0x1 | 22 | #define MEM_OPERATION_LOAD 0x1 |
22 | #define MEM_OPERATION_STORE 0x2 | 23 | #define MEM_OPERATION_STORE 0x2 |
@@ -249,8 +250,8 @@ static int report_raw_events(struct perf_mem *mem) | |||
249 | struct perf_session *session = perf_session__new(&data, false, | 250 | struct perf_session *session = perf_session__new(&data, false, |
250 | &mem->tool); | 251 | &mem->tool); |
251 | 252 | ||
252 | if (session == NULL) | 253 | if (IS_ERR(session)) |
253 | return -1; | 254 | return PTR_ERR(session); |
254 | 255 | ||
255 | if (mem->cpu_list) { | 256 | if (mem->cpu_list) { |
256 | ret = perf_session__cpu_bitmap(session, mem->cpu_list, | 257 | ret = perf_session__cpu_bitmap(session, mem->cpu_list, |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 4bd11c918e73..3f66a49a997f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include <signal.h> | 54 | #include <signal.h> |
55 | #include <sys/mman.h> | 55 | #include <sys/mman.h> |
56 | #include <sys/wait.h> | 56 | #include <sys/wait.h> |
57 | #include <linux/err.h> | ||
57 | #include <linux/string.h> | 58 | #include <linux/string.h> |
58 | #include <linux/time64.h> | 59 | #include <linux/time64.h> |
59 | #include <linux/zalloc.h> | 60 | #include <linux/zalloc.h> |
@@ -1354,9 +1355,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) | |||
1354 | } | 1355 | } |
1355 | 1356 | ||
1356 | session = perf_session__new(data, false, tool); | 1357 | session = perf_session__new(data, false, tool); |
1357 | if (session == NULL) { | 1358 | if (IS_ERR(session)) { |
1358 | pr_err("Perf session creation failed.\n"); | 1359 | pr_err("Perf session creation failed.\n"); |
1359 | return -1; | 1360 | return PTR_ERR(session); |
1360 | } | 1361 | } |
1361 | 1362 | ||
1362 | fd = perf_data__fd(data); | 1363 | fd = perf_data__fd(data); |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 3047e5169d9d..aae0e57c60fb 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -1269,8 +1269,8 @@ int cmd_report(int argc, const char **argv) | |||
1269 | 1269 | ||
1270 | repeat: | 1270 | repeat: |
1271 | session = perf_session__new(&data, false, &report.tool); | 1271 | session = perf_session__new(&data, false, &report.tool); |
1272 | if (session == NULL) | 1272 | if (IS_ERR(session)) |
1273 | return -1; | 1273 | return PTR_ERR(session); |
1274 | 1274 | ||
1275 | ret = evswitch__init(&report.evswitch, session->evlist, stderr); | 1275 | ret = evswitch__init(&report.evswitch, session->evlist, stderr); |
1276 | if (ret) | 1276 | if (ret) |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index f0b828c201cc..079e67a36904 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <api/fs/fs.h> | 40 | #include <api/fs/fs.h> |
41 | #include <perf/cpumap.h> | 41 | #include <perf/cpumap.h> |
42 | #include <linux/time64.h> | 42 | #include <linux/time64.h> |
43 | #include <linux/err.h> | ||
43 | 44 | ||
44 | #include <linux/ctype.h> | 45 | #include <linux/ctype.h> |
45 | 46 | ||
@@ -1797,9 +1798,9 @@ static int perf_sched__read_events(struct perf_sched *sched) | |||
1797 | int rc = -1; | 1798 | int rc = -1; |
1798 | 1799 | ||
1799 | session = perf_session__new(&data, false, &sched->tool); | 1800 | session = perf_session__new(&data, false, &sched->tool); |
1800 | if (session == NULL) { | 1801 | if (IS_ERR(session)) { |
1801 | pr_debug("No Memory for session\n"); | 1802 | pr_debug("Error creating perf session"); |
1802 | return -1; | 1803 | return PTR_ERR(session); |
1803 | } | 1804 | } |
1804 | 1805 | ||
1805 | symbol__init(&session->header.env); | 1806 | symbol__init(&session->header.env); |
@@ -2989,8 +2990,8 @@ static int perf_sched__timehist(struct perf_sched *sched) | |||
2989 | symbol_conf.use_callchain = sched->show_callchain; | 2990 | symbol_conf.use_callchain = sched->show_callchain; |
2990 | 2991 | ||
2991 | session = perf_session__new(&data, false, &sched->tool); | 2992 | session = perf_session__new(&data, false, &sched->tool); |
2992 | if (session == NULL) | 2993 | if (IS_ERR(session)) |
2993 | return -ENOMEM; | 2994 | return PTR_ERR(session); |
2994 | 2995 | ||
2995 | evlist = session->evlist; | 2996 | evlist = session->evlist; |
2996 | 2997 | ||
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index e079b34201f2..a17a9306bdf6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <subcmd/pager.h> | 53 | #include <subcmd/pager.h> |
54 | #include <perf/evlist.h> | 54 | #include <perf/evlist.h> |
55 | #include <linux/err.h> | ||
55 | #include "util/record.h" | 56 | #include "util/record.h" |
56 | #include "util/util.h" | 57 | #include "util/util.h" |
57 | #include "perf.h" | 58 | #include "perf.h" |
@@ -3083,8 +3084,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array, int num, | |||
3083 | int i = 0; | 3084 | int i = 0; |
3084 | 3085 | ||
3085 | session = perf_session__new(&data, false, NULL); | 3086 | session = perf_session__new(&data, false, NULL); |
3086 | if (!session) | 3087 | if (IS_ERR(session)) |
3087 | return -1; | 3088 | return PTR_ERR(session); |
3088 | 3089 | ||
3089 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); | 3090 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
3090 | 3091 | ||
@@ -3754,8 +3755,8 @@ int cmd_script(int argc, const char **argv) | |||
3754 | } | 3755 | } |
3755 | 3756 | ||
3756 | session = perf_session__new(&data, false, &script.tool); | 3757 | session = perf_session__new(&data, false, &script.tool); |
3757 | if (session == NULL) | 3758 | if (IS_ERR(session)) |
3758 | return -1; | 3759 | return PTR_ERR(session); |
3759 | 3760 | ||
3760 | if (header || header_only) { | 3761 | if (header || header_only) { |
3761 | script.tool.show_feat_hdr = SHOW_FEAT_HEADER; | 3762 | script.tool.show_feat_hdr = SHOW_FEAT_HEADER; |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 60cdd383af81..f7d13326b830 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -83,6 +83,7 @@ | |||
83 | #include <unistd.h> | 83 | #include <unistd.h> |
84 | #include <sys/time.h> | 84 | #include <sys/time.h> |
85 | #include <sys/resource.h> | 85 | #include <sys/resource.h> |
86 | #include <linux/err.h> | ||
86 | 87 | ||
87 | #include <linux/ctype.h> | 88 | #include <linux/ctype.h> |
88 | #include <perf/evlist.h> | 89 | #include <perf/evlist.h> |
@@ -1436,9 +1437,9 @@ static int __cmd_record(int argc, const char **argv) | |||
1436 | } | 1437 | } |
1437 | 1438 | ||
1438 | session = perf_session__new(data, false, NULL); | 1439 | session = perf_session__new(data, false, NULL); |
1439 | if (session == NULL) { | 1440 | if (IS_ERR(session)) { |
1440 | pr_err("Perf session creation failed.\n"); | 1441 | pr_err("Perf session creation failed\n"); |
1441 | return -1; | 1442 | return PTR_ERR(session); |
1442 | } | 1443 | } |
1443 | 1444 | ||
1444 | init_features(session); | 1445 | init_features(session); |
@@ -1635,8 +1636,8 @@ static int __cmd_report(int argc, const char **argv) | |||
1635 | perf_stat.data.mode = PERF_DATA_MODE_READ; | 1636 | perf_stat.data.mode = PERF_DATA_MODE_READ; |
1636 | 1637 | ||
1637 | session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); | 1638 | session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); |
1638 | if (session == NULL) | 1639 | if (IS_ERR(session)) |
1639 | return -1; | 1640 | return PTR_ERR(session); |
1640 | 1641 | ||
1641 | perf_stat.session = session; | 1642 | perf_stat.session = session; |
1642 | stat_config.output = stderr; | 1643 | stat_config.output = stderr; |
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index e0e822695a29..9e84fae9b096 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "util/tool.h" | 35 | #include "util/tool.h" |
36 | #include "util/data.h" | 36 | #include "util/data.h" |
37 | #include "util/debug.h" | 37 | #include "util/debug.h" |
38 | #include <linux/err.h> | ||
38 | 39 | ||
39 | #ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE | 40 | #ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE |
40 | FILE *open_memstream(char **ptr, size_t *sizeloc); | 41 | FILE *open_memstream(char **ptr, size_t *sizeloc); |
@@ -1601,8 +1602,8 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name) | |||
1601 | &tchart->tool); | 1602 | &tchart->tool); |
1602 | int ret = -EINVAL; | 1603 | int ret = -EINVAL; |
1603 | 1604 | ||
1604 | if (session == NULL) | 1605 | if (IS_ERR(session)) |
1605 | return -1; | 1606 | return PTR_ERR(session); |
1606 | 1607 | ||
1607 | symbol__init(&session->header.env); | 1608 | symbol__init(&session->header.env); |
1608 | 1609 | ||
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b052470f89b4..8da3c939e6b0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -77,6 +77,7 @@ | |||
77 | #include <linux/stringify.h> | 77 | #include <linux/stringify.h> |
78 | #include <linux/time64.h> | 78 | #include <linux/time64.h> |
79 | #include <linux/types.h> | 79 | #include <linux/types.h> |
80 | #include <linux/err.h> | ||
80 | 81 | ||
81 | #include <linux/ctype.h> | 82 | #include <linux/ctype.h> |
82 | 83 | ||
@@ -1672,8 +1673,8 @@ int cmd_top(int argc, const char **argv) | |||
1672 | } | 1673 | } |
1673 | 1674 | ||
1674 | top.session = perf_session__new(NULL, false, NULL); | 1675 | top.session = perf_session__new(NULL, false, NULL); |
1675 | if (top.session == NULL) { | 1676 | if (IS_ERR(top.session)) { |
1676 | status = -1; | 1677 | status = PTR_ERR(top.session); |
1677 | goto out_delete_evlist; | 1678 | goto out_delete_evlist; |
1678 | } | 1679 | } |
1679 | 1680 | ||
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index f0f735093e21..a292658b4232 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -3585,8 +3585,8 @@ static int trace__replay(struct trace *trace) | |||
3585 | trace->multiple_threads = true; | 3585 | trace->multiple_threads = true; |
3586 | 3586 | ||
3587 | session = perf_session__new(&data, false, &trace->tool); | 3587 | session = perf_session__new(&data, false, &trace->tool); |
3588 | if (session == NULL) | 3588 | if (IS_ERR(session)) |
3589 | return -1; | 3589 | return PTR_ERR(session); |
3590 | 3590 | ||
3591 | if (trace->opts.target.pid) | 3591 | if (trace->opts.target.pid) |
3592 | symbol_conf.pid_list_str = strdup(trace->opts.target.pid); | 3592 | symbol_conf.pid_list_str = strdup(trace->opts.target.pid); |
diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 7d845d913d7d..4a800499d7c3 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "session.h" | 8 | #include "session.h" |
9 | #include "evlist.h" | 9 | #include "evlist.h" |
10 | #include "debug.h" | 10 | #include "debug.h" |
11 | #include <linux/err.h> | ||
11 | 12 | ||
12 | #define TEMPL "/tmp/perf-test-XXXXXX" | 13 | #define TEMPL "/tmp/perf-test-XXXXXX" |
13 | #define DATA_SIZE 10 | 14 | #define DATA_SIZE 10 |
@@ -39,7 +40,7 @@ static int session_write_header(char *path) | |||
39 | }; | 40 | }; |
40 | 41 | ||
41 | session = perf_session__new(&data, false, NULL); | 42 | session = perf_session__new(&data, false, NULL); |
42 | TEST_ASSERT_VAL("can't get session", session); | 43 | TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); |
43 | 44 | ||
44 | session->evlist = perf_evlist__new_default(); | 45 | session->evlist = perf_evlist__new_default(); |
45 | TEST_ASSERT_VAL("can't get evlist", session->evlist); | 46 | TEST_ASSERT_VAL("can't get evlist", session->evlist); |
@@ -70,7 +71,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) | |||
70 | int i; | 71 | int i; |
71 | 72 | ||
72 | session = perf_session__new(&data, false, NULL); | 73 | session = perf_session__new(&data, false, NULL); |
73 | TEST_ASSERT_VAL("can't get session", session); | 74 | TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); |
74 | 75 | ||
75 | /* On platforms with large numbers of CPUs process_cpu_topology() | 76 | /* On platforms with large numbers of CPUs process_cpu_topology() |
76 | * might issue an error while reading the perf.data file section | 77 | * might issue an error while reading the perf.data file section |
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index 0c268449959c..dbc772bfb04e 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "machine.h" | 30 | #include "machine.h" |
31 | #include "config.h" | 31 | #include "config.h" |
32 | #include <linux/ctype.h> | 32 | #include <linux/ctype.h> |
33 | #include <linux/err.h> | ||
33 | 34 | ||
34 | #define pr_N(n, fmt, ...) \ | 35 | #define pr_N(n, fmt, ...) \ |
35 | eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__) | 36 | eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__) |
@@ -1619,8 +1620,10 @@ int bt_convert__perf2ctf(const char *input, const char *path, | |||
1619 | err = -1; | 1620 | err = -1; |
1620 | /* perf.data session */ | 1621 | /* perf.data session */ |
1621 | session = perf_session__new(&data, 0, &c.tool); | 1622 | session = perf_session__new(&data, 0, &c.tool); |
1622 | if (!session) | 1623 | if (IS_ERR(session)) { |
1624 | err = PTR_ERR(session); | ||
1623 | goto free_writer; | 1625 | goto free_writer; |
1626 | } | ||
1624 | 1627 | ||
1625 | if (c.queue_size) { | 1628 | if (c.queue_size) { |
1626 | ordered_events__set_alloc_size(&session->ordered_events, | 1629 | ordered_events__set_alloc_size(&session->ordered_events, |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 58b5bc34ba12..a621c73bad42 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "../perf.h" | 34 | #include "../perf.h" |
35 | #include "arch/common.h" | 35 | #include "arch/common.h" |
36 | #include <internal/lib.h> | 36 | #include <internal/lib.h> |
37 | #include <linux/err.h> | ||
37 | 38 | ||
38 | #ifdef HAVE_ZSTD_SUPPORT | 39 | #ifdef HAVE_ZSTD_SUPPORT |
39 | static int perf_session__process_compressed_event(struct perf_session *session, | 40 | static int perf_session__process_compressed_event(struct perf_session *session, |
@@ -187,6 +188,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe, | |||
187 | struct perf_session *perf_session__new(struct perf_data *data, | 188 | struct perf_session *perf_session__new(struct perf_data *data, |
188 | bool repipe, struct perf_tool *tool) | 189 | bool repipe, struct perf_tool *tool) |
189 | { | 190 | { |
191 | int ret = -ENOMEM; | ||
190 | struct perf_session *session = zalloc(sizeof(*session)); | 192 | struct perf_session *session = zalloc(sizeof(*session)); |
191 | 193 | ||
192 | if (!session) | 194 | if (!session) |
@@ -201,13 +203,15 @@ struct perf_session *perf_session__new(struct perf_data *data, | |||
201 | 203 | ||
202 | perf_env__init(&session->header.env); | 204 | perf_env__init(&session->header.env); |
203 | if (data) { | 205 | if (data) { |
204 | if (perf_data__open(data)) | 206 | ret = perf_data__open(data); |
207 | if (ret < 0) | ||
205 | goto out_delete; | 208 | goto out_delete; |
206 | 209 | ||
207 | session->data = data; | 210 | session->data = data; |
208 | 211 | ||
209 | if (perf_data__is_read(data)) { | 212 | if (perf_data__is_read(data)) { |
210 | if (perf_session__open(session) < 0) | 213 | ret = perf_session__open(session); |
214 | if (ret < 0) | ||
211 | goto out_delete; | 215 | goto out_delete; |
212 | 216 | ||
213 | /* | 217 | /* |
@@ -222,8 +226,11 @@ struct perf_session *perf_session__new(struct perf_data *data, | |||
222 | perf_evlist__init_trace_event_sample_raw(session->evlist); | 226 | perf_evlist__init_trace_event_sample_raw(session->evlist); |
223 | 227 | ||
224 | /* Open the directory data. */ | 228 | /* Open the directory data. */ |
225 | if (data->is_dir && perf_data__open_dir(data)) | 229 | if (data->is_dir) { |
230 | ret = perf_data__open_dir(data); | ||
231 | if (ret) | ||
226 | goto out_delete; | 232 | goto out_delete; |
233 | } | ||
227 | } | 234 | } |
228 | } else { | 235 | } else { |
229 | session->machines.host.env = &perf_env; | 236 | session->machines.host.env = &perf_env; |
@@ -256,7 +263,7 @@ struct perf_session *perf_session__new(struct perf_data *data, | |||
256 | out_delete: | 263 | out_delete: |
257 | perf_session__delete(session); | 264 | perf_session__delete(session); |
258 | out: | 265 | out: |
259 | return NULL; | 266 | return ERR_PTR(ret); |
260 | } | 267 | } |
261 | 268 | ||
262 | static void perf_session__delete_threads(struct perf_session *session) | 269 | static void perf_session__delete_threads(struct perf_session *session) |