diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-12 16:30:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-24 11:13:35 -0400 |
commit | a6d2a61ac653a85718aa61000d2648803f211ba3 (patch) | |
tree | 16b7c7bd53edbcf9d7927bfd50848f8b37b93128 /tools/lib | |
parent | b85119200dfaf51d361008d986d591156c7473d4 (diff) |
tools lib traceevent: Remove some die() calls
Cleaned event-parse.c this time, just propagate the errors and in handle
them the call sites.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-9ebpr2vgfk2qs2841i99sa8y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/traceevent/event-parse.c | 249 |
1 files changed, 175 insertions, 74 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 2091991691a6..b3bc13079c44 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <ctype.h> | 31 | #include <ctype.h> |
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | #include <stdint.h> | 33 | #include <stdint.h> |
34 | #include <limits.h> | ||
34 | 35 | ||
35 | #include "event-parse.h" | 36 | #include "event-parse.h" |
36 | #include "event-utils.h" | 37 | #include "event-utils.h" |
@@ -151,7 +152,9 @@ static int cmdline_init(struct pevent *pevent) | |||
151 | struct cmdline *cmdlines; | 152 | struct cmdline *cmdlines; |
152 | int i; | 153 | int i; |
153 | 154 | ||
154 | cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count); | 155 | cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count); |
156 | if (!cmdlines) | ||
157 | return -1; | ||
155 | 158 | ||
156 | i = 0; | 159 | i = 0; |
157 | while (cmdlist) { | 160 | while (cmdlist) { |
@@ -179,8 +182,8 @@ static char *find_cmdline(struct pevent *pevent, int pid) | |||
179 | if (!pid) | 182 | if (!pid) |
180 | return "<idle>"; | 183 | return "<idle>"; |
181 | 184 | ||
182 | if (!pevent->cmdlines) | 185 | if (!pevent->cmdlines && cmdline_init(pevent)) |
183 | cmdline_init(pevent); | 186 | return "<not enough memory for cmdlines!>"; |
184 | 187 | ||
185 | key.pid = pid; | 188 | key.pid = pid; |
186 | 189 | ||
@@ -208,8 +211,8 @@ int pevent_pid_is_registered(struct pevent *pevent, int pid) | |||
208 | if (!pid) | 211 | if (!pid) |
209 | return 1; | 212 | return 1; |
210 | 213 | ||
211 | if (!pevent->cmdlines) | 214 | if (!pevent->cmdlines && cmdline_init(pevent)) |
212 | cmdline_init(pevent); | 215 | return 0; |
213 | 216 | ||
214 | key.pid = pid; | 217 | key.pid = pid; |
215 | 218 | ||
@@ -251,10 +254,14 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid) | |||
251 | return -1; | 254 | return -1; |
252 | } | 255 | } |
253 | 256 | ||
254 | cmdlines[pevent->cmdline_count].pid = pid; | ||
255 | cmdlines[pevent->cmdline_count].comm = strdup(comm); | 257 | cmdlines[pevent->cmdline_count].comm = strdup(comm); |
256 | if (!cmdlines[pevent->cmdline_count].comm) | 258 | if (!cmdlines[pevent->cmdline_count].comm) { |
257 | die("malloc comm"); | 259 | free(cmdlines); |
260 | errno = ENOMEM; | ||
261 | return -1; | ||
262 | } | ||
263 | |||
264 | cmdlines[pevent->cmdline_count].pid = pid; | ||
258 | 265 | ||
259 | if (cmdlines[pevent->cmdline_count].comm) | 266 | if (cmdlines[pevent->cmdline_count].comm) |
260 | pevent->cmdline_count++; | 267 | pevent->cmdline_count++; |
@@ -281,10 +288,15 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid) | |||
281 | if (pevent->cmdlines) | 288 | if (pevent->cmdlines) |
282 | return add_new_comm(pevent, comm, pid); | 289 | return add_new_comm(pevent, comm, pid); |
283 | 290 | ||
284 | item = malloc_or_die(sizeof(*item)); | 291 | item = malloc(sizeof(*item)); |
292 | if (!item) | ||
293 | return -1; | ||
294 | |||
285 | item->comm = strdup(comm); | 295 | item->comm = strdup(comm); |
286 | if (!item->comm) | 296 | if (!item->comm) { |
287 | die("malloc comm"); | 297 | free(item); |
298 | return -1; | ||
299 | } | ||
288 | item->pid = pid; | 300 | item->pid = pid; |
289 | item->next = pevent->cmdlist; | 301 | item->next = pevent->cmdlist; |
290 | 302 | ||
@@ -348,7 +360,10 @@ static int func_map_init(struct pevent *pevent) | |||
348 | struct func_map *func_map; | 360 | struct func_map *func_map; |
349 | int i; | 361 | int i; |
350 | 362 | ||
351 | func_map = malloc_or_die(sizeof(*func_map) * (pevent->func_count + 1)); | 363 | func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1)); |
364 | if (!func_map) | ||
365 | return -1; | ||
366 | |||
352 | funclist = pevent->funclist; | 367 | funclist = pevent->funclist; |
353 | 368 | ||
354 | i = 0; | 369 | i = 0; |
@@ -448,25 +463,36 @@ pevent_find_function_address(struct pevent *pevent, unsigned long long addr) | |||
448 | int pevent_register_function(struct pevent *pevent, char *func, | 463 | int pevent_register_function(struct pevent *pevent, char *func, |
449 | unsigned long long addr, char *mod) | 464 | unsigned long long addr, char *mod) |
450 | { | 465 | { |
451 | struct func_list *item; | 466 | struct func_list *item = malloc(sizeof(*item)); |
452 | 467 | ||
453 | item = malloc_or_die(sizeof(*item)); | 468 | if (!item) |
469 | return -1; | ||
454 | 470 | ||
455 | item->next = pevent->funclist; | 471 | item->next = pevent->funclist; |
456 | item->func = strdup(func); | 472 | item->func = strdup(func); |
457 | if (mod) | 473 | if (!item->func) |
474 | goto out_free; | ||
475 | |||
476 | if (mod) { | ||
458 | item->mod = strdup(mod); | 477 | item->mod = strdup(mod); |
459 | else | 478 | if (!item->mod) |
479 | goto out_free_func; | ||
480 | } else | ||
460 | item->mod = NULL; | 481 | item->mod = NULL; |
461 | item->addr = addr; | 482 | item->addr = addr; |
462 | 483 | ||
463 | if (!item->func || (mod && !item->mod)) | ||
464 | die("malloc func"); | ||
465 | |||
466 | pevent->funclist = item; | 484 | pevent->funclist = item; |
467 | pevent->func_count++; | 485 | pevent->func_count++; |
468 | 486 | ||
469 | return 0; | 487 | return 0; |
488 | |||
489 | out_free_func: | ||
490 | free(item->func); | ||
491 | item->func = NULL; | ||
492 | out_free: | ||
493 | free(item); | ||
494 | errno = ENOMEM; | ||
495 | return -1; | ||
470 | } | 496 | } |
471 | 497 | ||
472 | /** | 498 | /** |
@@ -517,14 +543,16 @@ static int printk_cmp(const void *a, const void *b) | |||
517 | return 0; | 543 | return 0; |
518 | } | 544 | } |
519 | 545 | ||
520 | static void printk_map_init(struct pevent *pevent) | 546 | static int printk_map_init(struct pevent *pevent) |
521 | { | 547 | { |
522 | struct printk_list *printklist; | 548 | struct printk_list *printklist; |
523 | struct printk_list *item; | 549 | struct printk_list *item; |
524 | struct printk_map *printk_map; | 550 | struct printk_map *printk_map; |
525 | int i; | 551 | int i; |
526 | 552 | ||
527 | printk_map = malloc_or_die(sizeof(*printk_map) * (pevent->printk_count + 1)); | 553 | printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1)); |
554 | if (!printk_map) | ||
555 | return -1; | ||
528 | 556 | ||
529 | printklist = pevent->printklist; | 557 | printklist = pevent->printklist; |
530 | 558 | ||
@@ -542,6 +570,8 @@ static void printk_map_init(struct pevent *pevent) | |||
542 | 570 | ||
543 | pevent->printk_map = printk_map; | 571 | pevent->printk_map = printk_map; |
544 | pevent->printklist = NULL; | 572 | pevent->printklist = NULL; |
573 | |||
574 | return 0; | ||
545 | } | 575 | } |
546 | 576 | ||
547 | static struct printk_map * | 577 | static struct printk_map * |
@@ -550,8 +580,8 @@ find_printk(struct pevent *pevent, unsigned long long addr) | |||
550 | struct printk_map *printk; | 580 | struct printk_map *printk; |
551 | struct printk_map key; | 581 | struct printk_map key; |
552 | 582 | ||
553 | if (!pevent->printk_map) | 583 | if (!pevent->printk_map && printk_map_init(pevent)) |
554 | printk_map_init(pevent); | 584 | return NULL; |
555 | 585 | ||
556 | key.addr = addr; | 586 | key.addr = addr; |
557 | 587 | ||
@@ -573,21 +603,27 @@ find_printk(struct pevent *pevent, unsigned long long addr) | |||
573 | int pevent_register_print_string(struct pevent *pevent, char *fmt, | 603 | int pevent_register_print_string(struct pevent *pevent, char *fmt, |
574 | unsigned long long addr) | 604 | unsigned long long addr) |
575 | { | 605 | { |
576 | struct printk_list *item; | 606 | struct printk_list *item = malloc(sizeof(*item)); |
577 | 607 | ||
578 | item = malloc_or_die(sizeof(*item)); | 608 | if (!item) |
609 | return -1; | ||
579 | 610 | ||
580 | item->next = pevent->printklist; | 611 | item->next = pevent->printklist; |
581 | item->printk = strdup(fmt); | ||
582 | item->addr = addr; | 612 | item->addr = addr; |
583 | 613 | ||
614 | item->printk = strdup(fmt); | ||
584 | if (!item->printk) | 615 | if (!item->printk) |
585 | die("malloc fmt"); | 616 | goto out_free; |
586 | 617 | ||
587 | pevent->printklist = item; | 618 | pevent->printklist = item; |
588 | pevent->printk_count++; | 619 | pevent->printk_count++; |
589 | 620 | ||
590 | return 0; | 621 | return 0; |
622 | |||
623 | out_free: | ||
624 | free(item); | ||
625 | errno = ENOMEM; | ||
626 | return -1; | ||
591 | } | 627 | } |
592 | 628 | ||
593 | /** | 629 | /** |
@@ -615,14 +651,15 @@ static struct event_format *alloc_event(void) | |||
615 | return calloc(1, sizeof(struct event_format)); | 651 | return calloc(1, sizeof(struct event_format)); |
616 | } | 652 | } |
617 | 653 | ||
618 | static void add_event(struct pevent *pevent, struct event_format *event) | 654 | static int add_event(struct pevent *pevent, struct event_format *event) |
619 | { | 655 | { |
620 | int i; | 656 | int i; |
657 | struct event_format **events = realloc(pevent->events, sizeof(event) * | ||
658 | (pevent->nr_events + 1)); | ||
659 | if (!events) | ||
660 | return -1; | ||
621 | 661 | ||
622 | pevent->events = realloc(pevent->events, sizeof(event) * | 662 | pevent->events = events; |
623 | (pevent->nr_events + 1)); | ||
624 | if (!pevent->events) | ||
625 | die("Can not allocate events"); | ||
626 | 663 | ||
627 | for (i = 0; i < pevent->nr_events; i++) { | 664 | for (i = 0; i < pevent->nr_events; i++) { |
628 | if (pevent->events[i]->id > event->id) | 665 | if (pevent->events[i]->id > event->id) |
@@ -637,6 +674,8 @@ static void add_event(struct pevent *pevent, struct event_format *event) | |||
637 | pevent->nr_events++; | 674 | pevent->nr_events++; |
638 | 675 | ||
639 | event->pevent = pevent; | 676 | event->pevent = pevent; |
677 | |||
678 | return 0; | ||
640 | } | 679 | } |
641 | 680 | ||
642 | static int event_item_type(enum event_type type) | 681 | static int event_item_type(enum event_type type) |
@@ -1751,8 +1790,10 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1751 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { | 1790 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { |
1752 | char *new_atom; | 1791 | char *new_atom; |
1753 | 1792 | ||
1754 | if (left->type != PRINT_ATOM) | 1793 | if (left->type != PRINT_ATOM) { |
1755 | die("bad pointer type"); | 1794 | do_warning("bad pointer type"); |
1795 | goto out_free; | ||
1796 | } | ||
1756 | new_atom = realloc(left->atom.atom, | 1797 | new_atom = realloc(left->atom.atom, |
1757 | strlen(left->atom.atom) + 3); | 1798 | strlen(left->atom.atom) + 3); |
1758 | if (!new_atom) | 1799 | if (!new_atom) |
@@ -1870,7 +1911,11 @@ eval_type_str(unsigned long long val, const char *type, int pointer) | |||
1870 | return val; | 1911 | return val; |
1871 | } | 1912 | } |
1872 | 1913 | ||
1873 | ref = malloc_or_die(len); | 1914 | ref = malloc(len); |
1915 | if (!ref) { | ||
1916 | do_warning("%s: not enough memory!", __func__); | ||
1917 | return val; | ||
1918 | } | ||
1874 | memcpy(ref, type, len); | 1919 | memcpy(ref, type, len); |
1875 | 1920 | ||
1876 | /* chop off the " *" */ | 1921 | /* chop off the " *" */ |
@@ -1947,8 +1992,10 @@ eval_type_str(unsigned long long val, const char *type, int pointer) | |||
1947 | static unsigned long long | 1992 | static unsigned long long |
1948 | eval_type(unsigned long long val, struct print_arg *arg, int pointer) | 1993 | eval_type(unsigned long long val, struct print_arg *arg, int pointer) |
1949 | { | 1994 | { |
1950 | if (arg->type != PRINT_TYPE) | 1995 | if (arg->type != PRINT_TYPE) { |
1951 | die("expected type argument"); | 1996 | do_warning("expected type argument"); |
1997 | return 0; | ||
1998 | } | ||
1952 | 1999 | ||
1953 | return eval_type_str(val, arg->typecast.type, pointer); | 2000 | return eval_type_str(val, arg->typecast.type, pointer); |
1954 | } | 2001 | } |
@@ -2133,7 +2180,7 @@ static char *arg_eval (struct print_arg *arg) | |||
2133 | case PRINT_STRING: | 2180 | case PRINT_STRING: |
2134 | case PRINT_BSTRING: | 2181 | case PRINT_BSTRING: |
2135 | default: | 2182 | default: |
2136 | die("invalid eval type %d", arg->type); | 2183 | do_warning("invalid eval type %d", arg->type); |
2137 | break; | 2184 | break; |
2138 | } | 2185 | } |
2139 | 2186 | ||
@@ -2431,8 +2478,10 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok) | |||
2431 | /* make this a typecast and contine */ | 2478 | /* make this a typecast and contine */ |
2432 | 2479 | ||
2433 | /* prevous must be an atom */ | 2480 | /* prevous must be an atom */ |
2434 | if (arg->type != PRINT_ATOM) | 2481 | if (arg->type != PRINT_ATOM) { |
2435 | die("previous needed to be PRINT_ATOM"); | 2482 | do_warning("previous needed to be PRINT_ATOM"); |
2483 | goto out_free; | ||
2484 | } | ||
2436 | 2485 | ||
2437 | item_arg = alloc_arg(); | 2486 | item_arg = alloc_arg(); |
2438 | 2487 | ||
@@ -2674,7 +2723,8 @@ process_arg_token(struct event_format *event, struct print_arg *arg, | |||
2674 | 2723 | ||
2675 | case EVENT_ERROR ... EVENT_NEWLINE: | 2724 | case EVENT_ERROR ... EVENT_NEWLINE: |
2676 | default: | 2725 | default: |
2677 | die("unexpected type %d", type); | 2726 | do_warning("unexpected type %d", type); |
2727 | return EVENT_ERROR; | ||
2678 | } | 2728 | } |
2679 | *tok = token; | 2729 | *tok = token; |
2680 | 2730 | ||
@@ -2921,8 +2971,10 @@ static int get_common_info(struct pevent *pevent, | |||
2921 | * All events should have the same common elements. | 2971 | * All events should have the same common elements. |
2922 | * Pick any event to find where the type is; | 2972 | * Pick any event to find where the type is; |
2923 | */ | 2973 | */ |
2924 | if (!pevent->events) | 2974 | if (!pevent->events) { |
2925 | die("no event_list!"); | 2975 | do_warning("no event_list!"); |
2976 | return -1; | ||
2977 | } | ||
2926 | 2978 | ||
2927 | event = pevent->events[0]; | 2979 | event = pevent->events[0]; |
2928 | field = pevent_find_common_field(event, type); | 2980 | field = pevent_find_common_field(event, type); |
@@ -3080,7 +3132,8 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3080 | if (!arg->field.field) { | 3132 | if (!arg->field.field) { |
3081 | arg->field.field = pevent_find_any_field(event, arg->field.name); | 3133 | arg->field.field = pevent_find_any_field(event, arg->field.name); |
3082 | if (!arg->field.field) | 3134 | if (!arg->field.field) |
3083 | die("field %s not found", arg->field.name); | 3135 | goto out_warning_field; |
3136 | |||
3084 | } | 3137 | } |
3085 | /* must be a number */ | 3138 | /* must be a number */ |
3086 | val = pevent_read_number(pevent, data + arg->field.field->offset, | 3139 | val = pevent_read_number(pevent, data + arg->field.field->offset, |
@@ -3141,8 +3194,10 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3141 | if (!larg->field.field) { | 3194 | if (!larg->field.field) { |
3142 | larg->field.field = | 3195 | larg->field.field = |
3143 | pevent_find_any_field(event, larg->field.name); | 3196 | pevent_find_any_field(event, larg->field.name); |
3144 | if (!larg->field.field) | 3197 | if (!larg->field.field) { |
3145 | die("field %s not found", larg->field.name); | 3198 | arg = larg; |
3199 | goto out_warning_field; | ||
3200 | } | ||
3146 | } | 3201 | } |
3147 | field_size = larg->field.field->elementsize; | 3202 | field_size = larg->field.field->elementsize; |
3148 | offset = larg->field.field->offset + | 3203 | offset = larg->field.field->offset + |
@@ -3178,7 +3233,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3178 | val = left != right; | 3233 | val = left != right; |
3179 | break; | 3234 | break; |
3180 | default: | 3235 | default: |
3181 | die("unknown op '%s'", arg->op.op); | 3236 | goto out_warning_op; |
3182 | } | 3237 | } |
3183 | break; | 3238 | break; |
3184 | case '~': | 3239 | case '~': |
@@ -3208,7 +3263,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3208 | val = left <= right; | 3263 | val = left <= right; |
3209 | break; | 3264 | break; |
3210 | default: | 3265 | default: |
3211 | die("unknown op '%s'", arg->op.op); | 3266 | goto out_warning_op; |
3212 | } | 3267 | } |
3213 | break; | 3268 | break; |
3214 | case '>': | 3269 | case '>': |
@@ -3223,12 +3278,13 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3223 | val = left >= right; | 3278 | val = left >= right; |
3224 | break; | 3279 | break; |
3225 | default: | 3280 | default: |
3226 | die("unknown op '%s'", arg->op.op); | 3281 | goto out_warning_op; |
3227 | } | 3282 | } |
3228 | break; | 3283 | break; |
3229 | case '=': | 3284 | case '=': |
3230 | if (arg->op.op[1] != '=') | 3285 | if (arg->op.op[1] != '=') |
3231 | die("unknown op '%s'", arg->op.op); | 3286 | goto out_warning_op; |
3287 | |||
3232 | val = left == right; | 3288 | val = left == right; |
3233 | break; | 3289 | break; |
3234 | case '-': | 3290 | case '-': |
@@ -3244,13 +3300,21 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
3244 | val = left * right; | 3300 | val = left * right; |
3245 | break; | 3301 | break; |
3246 | default: | 3302 | default: |
3247 | die("unknown op '%s'", arg->op.op); | 3303 | goto out_warning_op; |
3248 | } | 3304 | } |
3249 | break; | 3305 | break; |
3250 | default: /* not sure what to do there */ | 3306 | default: /* not sure what to do there */ |
3251 | return 0; | 3307 | return 0; |
3252 | } | 3308 | } |
3253 | return val; | 3309 | return val; |
3310 | |||
3311 | out_warning_op: | ||
3312 | do_warning("%s: unknown op '%s'", __func__, arg->op.op); | ||
3313 | return 0; | ||
3314 | |||
3315 | out_warning_field: | ||
3316 | do_warning("%s: field %s not found", __func__, arg->field.name); | ||
3317 | return 0; | ||
3254 | } | 3318 | } |
3255 | 3319 | ||
3256 | struct flag { | 3320 | struct flag { |
@@ -3327,8 +3391,10 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3327 | field = arg->field.field; | 3391 | field = arg->field.field; |
3328 | if (!field) { | 3392 | if (!field) { |
3329 | field = pevent_find_any_field(event, arg->field.name); | 3393 | field = pevent_find_any_field(event, arg->field.name); |
3330 | if (!field) | 3394 | if (!field) { |
3331 | die("field %s not found", arg->field.name); | 3395 | str = arg->field.name; |
3396 | goto out_warning_field; | ||
3397 | } | ||
3332 | arg->field.field = field; | 3398 | arg->field.field = field; |
3333 | } | 3399 | } |
3334 | /* Zero sized fields, mean the rest of the data */ | 3400 | /* Zero sized fields, mean the rest of the data */ |
@@ -3345,7 +3411,11 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3345 | trace_seq_printf(s, "%lx", addr); | 3411 | trace_seq_printf(s, "%lx", addr); |
3346 | break; | 3412 | break; |
3347 | } | 3413 | } |
3348 | str = malloc_or_die(len + 1); | 3414 | str = malloc(len + 1); |
3415 | if (!str) { | ||
3416 | do_warning("%s: not enough memory!", __func__); | ||
3417 | return; | ||
3418 | } | ||
3349 | memcpy(str, data + field->offset, len); | 3419 | memcpy(str, data + field->offset, len); |
3350 | str[len] = 0; | 3420 | str[len] = 0; |
3351 | print_str_to_seq(s, format, len_arg, str); | 3421 | print_str_to_seq(s, format, len_arg, str); |
@@ -3385,7 +3455,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3385 | str = arg->hex.field->field.name; | 3455 | str = arg->hex.field->field.name; |
3386 | field = pevent_find_any_field(event, str); | 3456 | field = pevent_find_any_field(event, str); |
3387 | if (!field) | 3457 | if (!field) |
3388 | die("field %s not found", str); | 3458 | goto out_warning_field; |
3389 | arg->hex.field->field.field = field; | 3459 | arg->hex.field->field.field = field; |
3390 | } | 3460 | } |
3391 | hex = data + field->offset; | 3461 | hex = data + field->offset; |
@@ -3437,6 +3507,11 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3437 | /* well... */ | 3507 | /* well... */ |
3438 | break; | 3508 | break; |
3439 | } | 3509 | } |
3510 | |||
3511 | return; | ||
3512 | |||
3513 | out_warning_field: | ||
3514 | do_warning("%s: field %s not found", __func__, arg->field.name); | ||
3440 | } | 3515 | } |
3441 | 3516 | ||
3442 | static unsigned long long | 3517 | static unsigned long long |
@@ -3463,7 +3538,11 @@ process_defined_func(struct trace_seq *s, void *data, int size, | |||
3463 | farg = arg->func.args; | 3538 | farg = arg->func.args; |
3464 | param = func_handle->params; | 3539 | param = func_handle->params; |
3465 | 3540 | ||
3466 | args = malloc_or_die(sizeof(*args) * func_handle->nr_args); | 3541 | ret = ULLONG_MAX; |
3542 | args = malloc(sizeof(*args) * func_handle->nr_args); | ||
3543 | if (!args) | ||
3544 | goto out; | ||
3545 | |||
3467 | for (i = 0; i < func_handle->nr_args; i++) { | 3546 | for (i = 0; i < func_handle->nr_args; i++) { |
3468 | switch (param->type) { | 3547 | switch (param->type) { |
3469 | case PEVENT_FUNC_ARG_INT: | 3548 | case PEVENT_FUNC_ARG_INT: |
@@ -3475,12 +3554,18 @@ process_defined_func(struct trace_seq *s, void *data, int size, | |||
3475 | trace_seq_init(&str); | 3554 | trace_seq_init(&str); |
3476 | print_str_arg(&str, data, size, event, "%s", -1, farg); | 3555 | print_str_arg(&str, data, size, event, "%s", -1, farg); |
3477 | trace_seq_terminate(&str); | 3556 | trace_seq_terminate(&str); |
3478 | string = malloc_or_die(sizeof(*string)); | 3557 | string = malloc(sizeof(*string)); |
3558 | if (!string) { | ||
3559 | do_warning("%s(%d): malloc str", __func__, __LINE__); | ||
3560 | goto out_free; | ||
3561 | } | ||
3479 | string->next = strings; | 3562 | string->next = strings; |
3480 | string->str = strdup(str.buffer); | 3563 | string->str = strdup(str.buffer); |
3481 | if (!string->str) | 3564 | if (!string->str) { |
3482 | die("malloc str"); | 3565 | free(string); |
3483 | 3566 | do_warning("%s(%d): malloc str", __func__, __LINE__); | |
3567 | goto out_free; | ||
3568 | } | ||
3484 | args[i] = (uintptr_t)string->str; | 3569 | args[i] = (uintptr_t)string->str; |
3485 | strings = string; | 3570 | strings = string; |
3486 | trace_seq_destroy(&str); | 3571 | trace_seq_destroy(&str); |
@@ -3490,14 +3575,15 @@ process_defined_func(struct trace_seq *s, void *data, int size, | |||
3490 | * Something went totally wrong, this is not | 3575 | * Something went totally wrong, this is not |
3491 | * an input error, something in this code broke. | 3576 | * an input error, something in this code broke. |
3492 | */ | 3577 | */ |
3493 | die("Unexpected end of arguments\n"); | 3578 | do_warning("Unexpected end of arguments\n"); |
3494 | break; | 3579 | goto out_free; |
3495 | } | 3580 | } |
3496 | farg = farg->next; | 3581 | farg = farg->next; |
3497 | param = param->next; | 3582 | param = param->next; |
3498 | } | 3583 | } |
3499 | 3584 | ||
3500 | ret = (*func_handle->func)(s, args); | 3585 | ret = (*func_handle->func)(s, args); |
3586 | out_free: | ||
3501 | free(args); | 3587 | free(args); |
3502 | while (strings) { | 3588 | while (strings) { |
3503 | string = strings; | 3589 | string = strings; |
@@ -3538,11 +3624,15 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3538 | 3624 | ||
3539 | if (!field) { | 3625 | if (!field) { |
3540 | field = pevent_find_field(event, "buf"); | 3626 | field = pevent_find_field(event, "buf"); |
3541 | if (!field) | 3627 | if (!field) { |
3542 | die("can't find buffer field for binary printk"); | 3628 | do_warning("can't find buffer field for binary printk"); |
3629 | return NULL; | ||
3630 | } | ||
3543 | ip_field = pevent_find_field(event, "ip"); | 3631 | ip_field = pevent_find_field(event, "ip"); |
3544 | if (!ip_field) | 3632 | if (!ip_field) { |
3545 | die("can't find ip field for binary printk"); | 3633 | do_warning("can't find ip field for binary printk"); |
3634 | return NULL; | ||
3635 | } | ||
3546 | pevent->bprint_buf_field = field; | 3636 | pevent->bprint_buf_field = field; |
3547 | pevent->bprint_ip_field = ip_field; | 3637 | pevent->bprint_ip_field = ip_field; |
3548 | } | 3638 | } |
@@ -3637,7 +3727,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3637 | arg->type = PRINT_BSTRING; | 3727 | arg->type = PRINT_BSTRING; |
3638 | arg->string.string = strdup(bptr); | 3728 | arg->string.string = strdup(bptr); |
3639 | if (!arg->string.string) | 3729 | if (!arg->string.string) |
3640 | break; | 3730 | goto out_free; |
3641 | bptr += strlen(bptr) + 1; | 3731 | bptr += strlen(bptr) + 1; |
3642 | *next = arg; | 3732 | *next = arg; |
3643 | next = &arg->next; | 3733 | next = &arg->next; |
@@ -3669,8 +3759,10 @@ get_bprint_format(void *data, int size __maybe_unused, | |||
3669 | 3759 | ||
3670 | if (!field) { | 3760 | if (!field) { |
3671 | field = pevent_find_field(event, "fmt"); | 3761 | field = pevent_find_field(event, "fmt"); |
3672 | if (!field) | 3762 | if (!field) { |
3673 | die("can't find format field for binary printk"); | 3763 | do_warning("can't find format field for binary printk"); |
3764 | return NULL; | ||
3765 | } | ||
3674 | pevent->bprint_fmt_field = field; | 3766 | pevent->bprint_fmt_field = field; |
3675 | } | 3767 | } |
3676 | 3768 | ||
@@ -3723,8 +3815,11 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size, | |||
3723 | if (!arg->field.field) { | 3815 | if (!arg->field.field) { |
3724 | arg->field.field = | 3816 | arg->field.field = |
3725 | pevent_find_any_field(event, arg->field.name); | 3817 | pevent_find_any_field(event, arg->field.name); |
3726 | if (!arg->field.field) | 3818 | if (!arg->field.field) { |
3727 | die("field %s not found", arg->field.name); | 3819 | do_warning("%s: field %s not found", |
3820 | __func__, arg->field.name); | ||
3821 | return; | ||
3822 | } | ||
3728 | } | 3823 | } |
3729 | if (arg->field.field->size != 6) { | 3824 | if (arg->field.field->size != 6) { |
3730 | trace_seq_printf(s, "INVALIDMAC"); | 3825 | trace_seq_printf(s, "INVALIDMAC"); |
@@ -4380,7 +4475,10 @@ get_event_fields(const char *type, const char *name, | |||
4380 | struct format_field *field; | 4475 | struct format_field *field; |
4381 | int i = 0; | 4476 | int i = 0; |
4382 | 4477 | ||
4383 | fields = malloc_or_die(sizeof(*fields) * (count + 1)); | 4478 | fields = malloc(sizeof(*fields) * (count + 1)); |
4479 | if (!fields) | ||
4480 | return NULL; | ||
4481 | |||
4384 | for (field = list; field; field = field->next) { | 4482 | for (field = list; field; field = field->next) { |
4385 | fields[i++] = field; | 4483 | fields[i++] = field; |
4386 | if (i == count + 1) { | 4484 | if (i == count + 1) { |
@@ -4775,7 +4873,8 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, | |||
4775 | } | 4873 | } |
4776 | show_warning = 1; | 4874 | show_warning = 1; |
4777 | 4875 | ||
4778 | add_event(pevent, event); | 4876 | if (add_event(pevent, event)) |
4877 | goto event_alloc_failed; | ||
4779 | 4878 | ||
4780 | if (!ret && (event->flags & EVENT_FL_ISFTRACE)) { | 4879 | if (!ret && (event->flags & EVENT_FL_ISFTRACE)) { |
4781 | struct format_field *field; | 4880 | struct format_field *field; |
@@ -4808,7 +4907,9 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, | |||
4808 | event_parse_failed: | 4907 | event_parse_failed: |
4809 | event->flags |= EVENT_FL_FAILED; | 4908 | event->flags |= EVENT_FL_FAILED; |
4810 | /* still add it even if it failed */ | 4909 | /* still add it even if it failed */ |
4811 | add_event(pevent, event); | 4910 | if (add_event(pevent, event)) |
4911 | goto event_alloc_failed; | ||
4912 | |||
4812 | return ret; | 4913 | return ret; |
4813 | 4914 | ||
4814 | event_alloc_failed: | 4915 | event_alloc_failed: |