Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evsel: Propagate error info from tp_format

Propagate error info from tp_format via ERR_PTR to get it all the way
down to the parse-event.c tracepoint adding routines. Following
functions now return pointer with encoded error:

- tp_format
- trace_event__tp_format
- perf_evsel__newtp_idx
- perf_evsel__newtp

This affects several other places in perf, that cannot use pointer check
anymore, but must utilize the err.h interface, when getting error
information from above functions list.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Raphael Beamonte <raphael.beamonte@gmail.com>
Link: http://lkml.kernel.org/r/1441615087-13886-5-git-send-email-jolsa@kernel.org
[ Add two missing ERR_PTR() and one IS_ERR() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
8dd2a131 e2f9f8ea

+60 -24
+11 -8
tools/perf/builtin-trace.c
··· 38 38 #include <stdlib.h> 39 39 #include <sys/mman.h> 40 40 #include <linux/futex.h> 41 + #include <linux/err.h> 41 42 42 43 /* For older distros: */ 43 44 #ifndef MAP_STACK ··· 246 245 struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); 247 246 248 247 /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */ 249 - if (evsel == NULL) 248 + if (IS_ERR(evsel)) 250 249 evsel = perf_evsel__newtp("syscalls", direction); 251 250 252 - if (evsel) { 253 - if (perf_evsel__init_syscall_tp(evsel, handler)) 254 - goto out_delete; 255 - } 251 + if (IS_ERR(evsel)) 252 + return NULL; 253 + 254 + if (perf_evsel__init_syscall_tp(evsel, handler)) 255 + goto out_delete; 256 256 257 257 return evsel; 258 258 ··· 1707 1705 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); 1708 1706 sc->tp_format = trace_event__tp_format("syscalls", tp_name); 1709 1707 1710 - if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) { 1708 + if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) { 1711 1709 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); 1712 1710 sc->tp_format = trace_event__tp_format("syscalls", tp_name); 1713 1711 } 1714 1712 1715 - if (sc->tp_format == NULL) 1713 + if (IS_ERR(sc->tp_format)) 1716 1714 return -1; 1717 1715 1718 1716 sc->args = sc->tp_format->format.fields; ··· 2392 2390 static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist) 2393 2391 { 2394 2392 struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname"); 2395 - if (evsel == NULL) 2393 + 2394 + if (IS_ERR(evsel)) 2396 2395 return false; 2397 2396 2398 2397 if (perf_evsel__field(evsel, "pathname") == NULL) {
+8 -2
tools/perf/tests/evsel-tp-sched.c
··· 1 + #include <linux/err.h> 1 2 #include <traceevent/event-parse.h> 2 3 #include "evsel.h" 3 4 #include "tests.h" ··· 37 36 struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); 38 37 int ret = 0; 39 38 40 - if (evsel == NULL) { 41 - pr_debug("perf_evsel__new\n"); 39 + if (IS_ERR(evsel)) { 40 + pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel)); 42 41 return -1; 43 42 } 44 43 ··· 66 65 perf_evsel__delete(evsel); 67 66 68 67 evsel = perf_evsel__newtp("sched", "sched_wakeup"); 68 + 69 + if (IS_ERR(evsel)) { 70 + pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel)); 71 + return -1; 72 + } 69 73 70 74 if (perf_evsel__test_field(evsel, "comm", 16, true)) 71 75 ret = -1;
+2 -1
tools/perf/tests/mmap-basic.c
··· 3 3 #include "thread_map.h" 4 4 #include "cpumap.h" 5 5 #include "tests.h" 6 + #include <linux/err.h> 6 7 7 8 /* 8 9 * This test will generate random numbers of calls to some getpid syscalls, ··· 66 65 67 66 snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); 68 67 evsels[i] = perf_evsel__newtp("syscalls", name); 69 - if (evsels[i] == NULL) { 68 + if (IS_ERR(evsels[i])) { 70 69 pr_debug("perf_evsel__new\n"); 71 70 goto out_delete_evlist; 72 71 }
+2 -1
tools/perf/tests/openat-syscall-all-cpus.c
··· 1 1 #include <api/fs/fs.h> 2 + #include <linux/err.h> 2 3 #include "evsel.h" 3 4 #include "tests.h" 4 5 #include "thread_map.h" ··· 32 31 CPU_ZERO(&cpu_set); 33 32 34 33 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); 35 - if (evsel == NULL) { 34 + if (IS_ERR(evsel)) { 36 35 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); 37 36 pr_err("%s\n", errbuf); 38 37 goto out_thread_map_delete;
+2 -1
tools/perf/tests/openat-syscall-tp-fields.c
··· 1 + #include <linux/err.h> 1 2 #include "perf.h" 2 3 #include "evlist.h" 3 4 #include "evsel.h" ··· 31 30 } 32 31 33 32 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); 34 - if (evsel == NULL) { 33 + if (IS_ERR(evsel)) { 35 34 pr_debug("%s: perf_evsel__newtp\n", __func__); 36 35 goto out_delete_evlist; 37 36 }
+2 -1
tools/perf/tests/openat-syscall.c
··· 1 1 #include <api/fs/tracing_path.h> 2 + #include <linux/err.h> 2 3 #include "thread_map.h" 3 4 #include "evsel.h" 4 5 #include "debug.h" ··· 20 19 } 21 20 22 21 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); 23 - if (evsel == NULL) { 22 + if (IS_ERR(evsel)) { 24 23 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); 25 24 pr_err("%s\n", errbuf); 26 25 goto out_thread_map_delete;
+2 -1
tools/perf/util/evlist.c
··· 25 25 #include <linux/bitops.h> 26 26 #include <linux/hash.h> 27 27 #include <linux/log2.h> 28 + #include <linux/err.h> 28 29 29 30 static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); 30 31 static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); ··· 266 265 { 267 266 struct perf_evsel *evsel = perf_evsel__newtp(sys, name); 268 267 269 - if (evsel == NULL) 268 + if (IS_ERR(evsel)) 270 269 return -1; 271 270 272 271 evsel->handler = handler;
+13 -3
tools/perf/util/evsel.c
··· 13 13 #include <traceevent/event-parse.h> 14 14 #include <linux/hw_breakpoint.h> 15 15 #include <linux/perf_event.h> 16 + #include <linux/err.h> 16 17 #include <sys/resource.h> 17 18 #include "asm/bug.h" 18 19 #include "callchain.h" ··· 226 225 return evsel; 227 226 } 228 227 228 + /* 229 + * Returns pointer with encoded error via <linux/err.h> interface. 230 + */ 229 231 struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx) 230 232 { 231 233 struct perf_evsel *evsel = zalloc(perf_evsel__object.size); 234 + int err = -ENOMEM; 232 235 233 - if (evsel != NULL) { 236 + if (evsel == NULL) { 237 + goto out_err; 238 + } else { 234 239 struct perf_event_attr attr = { 235 240 .type = PERF_TYPE_TRACEPOINT, 236 241 .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | ··· 247 240 goto out_free; 248 241 249 242 evsel->tp_format = trace_event__tp_format(sys, name); 250 - if (evsel->tp_format == NULL) 243 + if (IS_ERR(evsel->tp_format)) { 244 + err = PTR_ERR(evsel->tp_format); 251 245 goto out_free; 246 + } 252 247 253 248 event_attr_init(&attr); 254 249 attr.config = evsel->tp_format->id; ··· 263 254 out_free: 264 255 zfree(&evsel->name); 265 256 free(evsel); 266 - return NULL; 257 + out_err: 258 + return ERR_PTR(err); 267 259 } 268 260 269 261 const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
+3
tools/perf/util/evsel.h
··· 160 160 161 161 struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx); 162 162 163 + /* 164 + * Returns pointer with encoded error via <linux/err.h> interface. 165 + */ 163 166 static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name) 164 167 { 165 168 return perf_evsel__newtp_idx(sys, name, 0);
+3 -3
tools/perf/util/parse-events.c
··· 1 1 #include <linux/hw_breakpoint.h> 2 + #include <linux/err.h> 2 3 #include "util.h" 3 4 #include "../perf.h" 4 5 #include "evlist.h" ··· 394 393 struct perf_evsel *evsel; 395 394 396 395 evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); 397 - if (!evsel) 398 - return -ENOMEM; 396 + if (IS_ERR(evsel)) 397 + return PTR_ERR(evsel); 399 398 400 399 list_add_tail(&evsel->node, list); 401 - 402 400 return 0; 403 401 } 404 402
+12 -3
tools/perf/util/trace-event.c
··· 7 7 #include <sys/stat.h> 8 8 #include <fcntl.h> 9 9 #include <linux/kernel.h> 10 + #include <linux/err.h> 10 11 #include <traceevent/event-parse.h> 11 12 #include <api/fs/tracing_path.h> 12 13 #include "trace-event.h" ··· 67 66 pevent_free(t->pevent); 68 67 } 69 68 69 + /* 70 + * Returns pointer with encoded error via <linux/err.h> interface. 71 + */ 70 72 static struct event_format* 71 73 tp_format(const char *sys, const char *name) 72 74 { ··· 78 74 char path[PATH_MAX]; 79 75 size_t size; 80 76 char *data; 77 + int err; 81 78 82 79 scnprintf(path, PATH_MAX, "%s/%s/%s/format", 83 80 tracing_events_path, sys, name); 84 81 85 - if (filename__read_str(path, &data, &size)) 86 - return NULL; 82 + err = filename__read_str(path, &data, &size); 83 + if (err) 84 + return ERR_PTR(err); 87 85 88 86 pevent_parse_format(pevent, &event, data, size, sys); 89 87 ··· 93 87 return event; 94 88 } 95 89 90 + /* 91 + * Returns pointer with encoded error via <linux/err.h> interface. 92 + */ 96 93 struct event_format* 97 94 trace_event__tp_format(const char *sys, const char *name) 98 95 { 99 96 if (!tevent_initialized && trace_event__init2()) 100 - return NULL; 97 + return ERR_PTR(-ENOMEM); 101 98 102 99 return tp_format(sys, name); 103 100 }