diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2010-04-12 13:17:49 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-04-14 16:28:45 -0400 |
commit | e334016f1d7250a6523b3a44ccecfe23af6e2f57 (patch) | |
tree | 376d8df547a43bd4288af2ec7ea4aa6aa6e8dd0e /tools/perf/util/probe-event.c | |
parent | 146a143948ed9e8b248c0ec59937f3e9e1bbc7e5 (diff) |
perf probe: Remove xzalloc() from util/probe-{event, finder}.c
Remove all xzalloc() calls from util/probe-{event,finder}.c since
it may cause 'sudden death' in utility functions and it makes
reusing it from other code difficult.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20100412171749.3790.33303.stgit@localhost6.localdomain6>
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r-- | tools/perf/util/probe-event.c | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index bd68f7b33b21..aacbf730b475 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -556,7 +556,9 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | |||
556 | fieldp = &arg->field; | 556 | fieldp = &arg->field; |
557 | 557 | ||
558 | do { | 558 | do { |
559 | *fieldp = xzalloc(sizeof(struct perf_probe_arg_field)); | 559 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); |
560 | if (*fieldp == NULL) | ||
561 | return -ENOMEM; | ||
560 | if (*tmp == '.') { | 562 | if (*tmp == '.') { |
561 | str = tmp + 1; | 563 | str = tmp + 1; |
562 | (*fieldp)->ref = false; | 564 | (*fieldp)->ref = false; |
@@ -608,7 +610,11 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev) | |||
608 | 610 | ||
609 | /* Copy arguments and ensure return probe has no C argument */ | 611 | /* Copy arguments and ensure return probe has no C argument */ |
610 | pev->nargs = argc - 1; | 612 | pev->nargs = argc - 1; |
611 | pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs); | 613 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
614 | if (pev->args == NULL) { | ||
615 | ret = -ENOMEM; | ||
616 | goto out; | ||
617 | } | ||
612 | for (i = 0; i < pev->nargs && ret >= 0; i++) { | 618 | for (i = 0; i < pev->nargs && ret >= 0; i++) { |
613 | ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]); | 619 | ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]); |
614 | if (ret >= 0 && | 620 | if (ret >= 0 && |
@@ -680,7 +686,11 @@ int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev) | |||
680 | tp->offset = 0; | 686 | tp->offset = 0; |
681 | 687 | ||
682 | tev->nargs = argc - 2; | 688 | tev->nargs = argc - 2; |
683 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); | 689 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
690 | if (tev->args == NULL) { | ||
691 | ret = -ENOMEM; | ||
692 | goto out; | ||
693 | } | ||
684 | for (i = 0; i < tev->nargs; i++) { | 694 | for (i = 0; i < tev->nargs; i++) { |
685 | p = strchr(argv[i + 2], '='); | 695 | p = strchr(argv[i + 2], '='); |
686 | if (p) /* We don't need which register is assigned. */ | 696 | if (p) /* We don't need which register is assigned. */ |
@@ -745,7 +755,11 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp) | |||
745 | char offs[32] = "", line[32] = "", file[32] = ""; | 755 | char offs[32] = "", line[32] = "", file[32] = ""; |
746 | int ret, len; | 756 | int ret, len; |
747 | 757 | ||
748 | buf = xzalloc(MAX_CMDLEN); | 758 | buf = zalloc(MAX_CMDLEN); |
759 | if (buf == NULL) { | ||
760 | ret = -ENOMEM; | ||
761 | goto error; | ||
762 | } | ||
749 | if (pp->offset) { | 763 | if (pp->offset) { |
750 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); | 764 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); |
751 | if (ret <= 0) | 765 | if (ret <= 0) |
@@ -781,7 +795,8 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp) | |||
781 | error: | 795 | error: |
782 | pr_debug("Failed to synthesize perf probe point: %s", | 796 | pr_debug("Failed to synthesize perf probe point: %s", |
783 | strerror(-ret)); | 797 | strerror(-ret)); |
784 | free(buf); | 798 | if (buf) |
799 | free(buf); | ||
785 | return NULL; | 800 | return NULL; |
786 | } | 801 | } |
787 | 802 | ||
@@ -890,7 +905,10 @@ char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev) | |||
890 | char *buf; | 905 | char *buf; |
891 | int i, len, ret; | 906 | int i, len, ret; |
892 | 907 | ||
893 | buf = xzalloc(MAX_CMDLEN); | 908 | buf = zalloc(MAX_CMDLEN); |
909 | if (buf == NULL) | ||
910 | return NULL; | ||
911 | |||
894 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu", | 912 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu", |
895 | tp->retprobe ? 'r' : 'p', | 913 | tp->retprobe ? 'r' : 'p', |
896 | tev->group, tev->event, | 914 | tev->group, tev->event, |
@@ -929,7 +947,9 @@ int convert_to_perf_probe_event(struct kprobe_trace_event *tev, | |||
929 | 947 | ||
930 | /* Convert trace_arg to probe_arg */ | 948 | /* Convert trace_arg to probe_arg */ |
931 | pev->nargs = tev->nargs; | 949 | pev->nargs = tev->nargs; |
932 | pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs); | 950 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
951 | if (pev->args == NULL) | ||
952 | return -ENOMEM; | ||
933 | for (i = 0; i < tev->nargs && ret >= 0; i++) | 953 | for (i = 0; i < tev->nargs && ret >= 0; i++) |
934 | if (tev->args[i].name) | 954 | if (tev->args[i].name) |
935 | pev->args[i].name = xstrdup(tev->args[i].name); | 955 | pev->args[i].name = xstrdup(tev->args[i].name); |
@@ -1326,25 +1346,31 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, | |||
1326 | struct kprobe_trace_event **tevs) | 1346 | struct kprobe_trace_event **tevs) |
1327 | { | 1347 | { |
1328 | struct symbol *sym; | 1348 | struct symbol *sym; |
1329 | int ntevs = 0, i; | 1349 | int ret = 0, i; |
1330 | struct kprobe_trace_event *tev; | 1350 | struct kprobe_trace_event *tev; |
1331 | 1351 | ||
1332 | /* Convert perf_probe_event with debuginfo */ | 1352 | /* Convert perf_probe_event with debuginfo */ |
1333 | ntevs = try_to_find_kprobe_trace_events(pev, tevs); | 1353 | ret = try_to_find_kprobe_trace_events(pev, tevs); |
1334 | if (ntevs != 0) | 1354 | if (ret != 0) |
1335 | return ntevs; | 1355 | return ret; |
1336 | 1356 | ||
1337 | /* Allocate trace event buffer */ | 1357 | /* Allocate trace event buffer */ |
1338 | ntevs = 1; | 1358 | tev = *tevs = zalloc(sizeof(struct kprobe_trace_event)); |
1339 | tev = *tevs = xzalloc(sizeof(struct kprobe_trace_event)); | 1359 | if (tev == NULL) |
1360 | return -ENOMEM; | ||
1340 | 1361 | ||
1341 | /* Copy parameters */ | 1362 | /* Copy parameters */ |
1342 | tev->point.symbol = xstrdup(pev->point.function); | 1363 | tev->point.symbol = xstrdup(pev->point.function); |
1343 | tev->point.offset = pev->point.offset; | 1364 | tev->point.offset = pev->point.offset; |
1344 | tev->nargs = pev->nargs; | 1365 | tev->nargs = pev->nargs; |
1345 | if (tev->nargs) { | 1366 | if (tev->nargs) { |
1346 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) | 1367 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) |
1347 | * tev->nargs); | 1368 | * tev->nargs); |
1369 | if (tev->args == NULL) { | ||
1370 | free(tev); | ||
1371 | *tevs = NULL; | ||
1372 | return -ENOMEM; | ||
1373 | } | ||
1348 | for (i = 0; i < tev->nargs; i++) { | 1374 | for (i = 0; i < tev->nargs; i++) { |
1349 | if (pev->args[i].name) | 1375 | if (pev->args[i].name) |
1350 | tev->args[i].name = xstrdup(pev->args[i].name); | 1376 | tev->args[i].name = xstrdup(pev->args[i].name); |
@@ -1360,9 +1386,14 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, | |||
1360 | if (!sym) { | 1386 | if (!sym) { |
1361 | pr_warning("Kernel symbol \'%s\' not found.\n", | 1387 | pr_warning("Kernel symbol \'%s\' not found.\n", |
1362 | tev->point.symbol); | 1388 | tev->point.symbol); |
1389 | clear_kprobe_trace_event(tev); | ||
1390 | free(tev); | ||
1391 | *tevs = NULL; | ||
1363 | return -ENOENT; | 1392 | return -ENOENT; |
1364 | } | 1393 | } else |
1365 | return ntevs; | 1394 | ret = 1; |
1395 | |||
1396 | return ret; | ||
1366 | } | 1397 | } |
1367 | 1398 | ||
1368 | struct __event_package { | 1399 | struct __event_package { |
@@ -1377,7 +1408,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | |||
1377 | int i, j, ret; | 1408 | int i, j, ret; |
1378 | struct __event_package *pkgs; | 1409 | struct __event_package *pkgs; |
1379 | 1410 | ||
1380 | pkgs = xzalloc(sizeof(struct __event_package) * npevs); | 1411 | pkgs = zalloc(sizeof(struct __event_package) * npevs); |
1412 | if (pkgs == NULL) | ||
1413 | return -ENOMEM; | ||
1381 | 1414 | ||
1382 | /* Init vmlinux path */ | 1415 | /* Init vmlinux path */ |
1383 | ret = init_vmlinux(); | 1416 | ret = init_vmlinux(); |