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 | |
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')
-rw-r--r-- | tools/perf/util/probe-event.c | 69 | ||||
-rw-r--r-- | tools/perf/util/probe-finder.c | 25 |
2 files changed, 69 insertions, 25 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(); |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 54daa91e901d..ce1ac827f3d2 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -111,7 +111,7 @@ static int strtailcmp(const char *s1, const char *s2) | |||
111 | /* Line number list operations */ | 111 | /* Line number list operations */ |
112 | 112 | ||
113 | /* Add a line to line number list */ | 113 | /* Add a line to line number list */ |
114 | static void line_list__add_line(struct list_head *head, unsigned int line) | 114 | static int line_list__add_line(struct list_head *head, unsigned int line) |
115 | { | 115 | { |
116 | struct line_node *ln; | 116 | struct line_node *ln; |
117 | struct list_head *p; | 117 | struct list_head *p; |
@@ -122,16 +122,19 @@ static void line_list__add_line(struct list_head *head, unsigned int line) | |||
122 | p = &ln->list; | 122 | p = &ln->list; |
123 | goto found; | 123 | goto found; |
124 | } else if (ln->line == line) /* Already exist */ | 124 | } else if (ln->line == line) /* Already exist */ |
125 | return ; | 125 | return 1; |
126 | } | 126 | } |
127 | /* List is empty, or the smallest entry */ | 127 | /* List is empty, or the smallest entry */ |
128 | p = head; | 128 | p = head; |
129 | found: | 129 | found: |
130 | pr_debug("line list: add a line %u\n", line); | 130 | pr_debug("line list: add a line %u\n", line); |
131 | ln = xzalloc(sizeof(struct line_node)); | 131 | ln = zalloc(sizeof(struct line_node)); |
132 | if (ln == NULL) | ||
133 | return -ENOMEM; | ||
132 | ln->line = line; | 134 | ln->line = line; |
133 | INIT_LIST_HEAD(&ln->list); | 135 | INIT_LIST_HEAD(&ln->list); |
134 | list_add(&ln->list, p); | 136 | list_add(&ln->list, p); |
137 | return 0; | ||
135 | } | 138 | } |
136 | 139 | ||
137 | /* Check if the line in line number list */ | 140 | /* Check if the line in line number list */ |
@@ -423,7 +426,9 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf) | |||
423 | 426 | ||
424 | tvar->value = xstrdup(regs); | 427 | tvar->value = xstrdup(regs); |
425 | if (ref) { | 428 | if (ref) { |
426 | tvar->ref = xzalloc(sizeof(struct kprobe_trace_arg_ref)); | 429 | tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); |
430 | if (tvar->ref == NULL) | ||
431 | return -ENOMEM; | ||
427 | tvar->ref->offset = (long)offs; | 432 | tvar->ref->offset = (long)offs; |
428 | } | 433 | } |
429 | return 0; | 434 | return 0; |
@@ -500,7 +505,9 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
500 | return -EINVAL; | 505 | return -EINVAL; |
501 | } | 506 | } |
502 | 507 | ||
503 | ref = xzalloc(sizeof(struct kprobe_trace_arg_ref)); | 508 | ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); |
509 | if (ref == NULL) | ||
510 | return -ENOMEM; | ||
504 | if (*ref_ptr) | 511 | if (*ref_ptr) |
505 | (*ref_ptr)->next = ref; | 512 | (*ref_ptr)->next = ref; |
506 | else | 513 | else |
@@ -680,7 +687,9 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
680 | 687 | ||
681 | /* Find each argument */ | 688 | /* Find each argument */ |
682 | tev->nargs = pf->pev->nargs; | 689 | tev->nargs = pf->pev->nargs; |
683 | tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); | 690 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
691 | if (tev->args == NULL) | ||
692 | return -ENOMEM; | ||
684 | for (i = 0; i < pf->pev->nargs; i++) { | 693 | for (i = 0; i < pf->pev->nargs; i++) { |
685 | pf->pvar = &pf->pev->args[i]; | 694 | pf->pvar = &pf->pev->args[i]; |
686 | pf->tvar = &tev->args[i]; | 695 | pf->tvar = &tev->args[i]; |
@@ -938,7 +947,9 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, | |||
938 | Dwarf *dbg; | 947 | Dwarf *dbg; |
939 | int ret = 0; | 948 | int ret = 0; |
940 | 949 | ||
941 | pf.tevs = xzalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES); | 950 | pf.tevs = zalloc(sizeof(struct kprobe_trace_event) * MAX_PROBES); |
951 | if (pf.tevs == NULL) | ||
952 | return -ENOMEM; | ||
942 | *tevs = pf.tevs; | 953 | *tevs = pf.tevs; |
943 | pf.ntevs = 0; | 954 | pf.ntevs = 0; |
944 | 955 | ||