aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-09-12 14:39:59 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-09-24 11:10:34 -0400
commit0dbca1e364aba20dba70d88c083239c5152440ac (patch)
tree06ff96717e807df7833fe41480dd5b9d1f988848 /tools/lib
parent3ce711a6abc27abce1554e1d671a8762b7187690 (diff)
tools lib traceevent: Use asprintf were applicable
Replacing the equivalent open coded malloc + sprintf bits. 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-ghokwtdw2hgmmmn7oa9s03r4@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.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index acf40381b48b..2e05d567353e 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -827,9 +827,9 @@ static enum event_type __read_token(char **tok)
827 switch (type) { 827 switch (type) {
828 case EVENT_NEWLINE: 828 case EVENT_NEWLINE:
829 case EVENT_DELIM: 829 case EVENT_DELIM:
830 *tok = malloc_or_die(2); 830 if (asprintf(tok, "%c", ch) < 0)
831 (*tok)[0] = ch; 831 return EVENT_ERROR;
832 (*tok)[1] = 0; 832
833 return type; 833 return type;
834 834
835 case EVENT_OP: 835 case EVENT_OP:
@@ -2777,10 +2777,8 @@ static int event_read_print(struct event_format *event)
2777 if (type == EVENT_DQUOTE) { 2777 if (type == EVENT_DQUOTE) {
2778 char *cat; 2778 char *cat;
2779 2779
2780 cat = malloc_or_die(strlen(event->print_fmt.format) + 2780 if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
2781 strlen(token) + 1); 2781 goto fail;
2782 strcpy(cat, event->print_fmt.format);
2783 strcat(cat, token);
2784 free_token(token); 2782 free_token(token);
2785 free_token(event->print_fmt.format); 2783 free_token(event->print_fmt.format);
2786 event->print_fmt.format = NULL; 2784 event->print_fmt.format = NULL;
@@ -3524,6 +3522,18 @@ process_defined_func(struct trace_seq *s, void *data, int size,
3524 return ret; 3522 return ret;
3525} 3523}
3526 3524
3525static void free_args(struct print_arg *args)
3526{
3527 struct print_arg *next;
3528
3529 while (args) {
3530 next = args->next;
3531
3532 free_arg(args);
3533 args = next;
3534 }
3535}
3536
3527static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event) 3537static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
3528{ 3538{
3529 struct pevent *pevent = event->pevent; 3539 struct pevent *pevent = event->pevent;
@@ -3559,8 +3569,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3559 next = &arg->next; 3569 next = &arg->next;
3560 3570
3561 arg->type = PRINT_ATOM; 3571 arg->type = PRINT_ATOM;
3562 arg->atom.atom = malloc_or_die(32); 3572
3563 sprintf(arg->atom.atom, "%lld", ip); 3573 if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
3574 goto out_free;
3564 3575
3565 /* skip the first "%pf : " */ 3576 /* skip the first "%pf : " */
3566 for (ptr = fmt + 6, bptr = data + field->offset; 3577 for (ptr = fmt + 6, bptr = data + field->offset;
@@ -3617,8 +3628,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3617 arg = alloc_arg(); 3628 arg = alloc_arg();
3618 arg->next = NULL; 3629 arg->next = NULL;
3619 arg->type = PRINT_ATOM; 3630 arg->type = PRINT_ATOM;
3620 arg->atom.atom = malloc_or_die(32); 3631 if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
3621 sprintf(arg->atom.atom, "%lld", val); 3632 free(arg);
3633 goto out_free;
3634 }
3622 *next = arg; 3635 *next = arg;
3623 next = &arg->next; 3636 next = &arg->next;
3624 /* 3637 /*
@@ -3646,18 +3659,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3646 } 3659 }
3647 3660
3648 return args; 3661 return args;
3649}
3650
3651static void free_args(struct print_arg *args)
3652{
3653 struct print_arg *next;
3654
3655 while (args) {
3656 next = args->next;
3657 3662
3658 free_arg(args); 3663out_free:
3659 args = next; 3664 free_args(args);
3660 } 3665 return NULL;
3661} 3666}
3662 3667
3663static char * 3668static char *
@@ -3684,9 +3689,8 @@ get_bprint_format(void *data, int size __maybe_unused,
3684 3689
3685 printk = find_printk(pevent, addr); 3690 printk = find_printk(pevent, addr);
3686 if (!printk) { 3691 if (!printk) {
3687 format = malloc_or_die(45); 3692 if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0)
3688 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n", 3693 return NULL;
3689 addr);
3690 return format; 3694 return format;
3691 } 3695 }
3692 3696
@@ -3694,8 +3698,8 @@ get_bprint_format(void *data, int size __maybe_unused,
3694 /* Remove any quotes. */ 3698 /* Remove any quotes. */
3695 if (*p == '"') 3699 if (*p == '"')
3696 p++; 3700 p++;
3697 format = malloc_or_die(strlen(p) + 10); 3701 if (asprintf(&format, "%s : %s", "%pf", p) < 0)
3698 sprintf(format, "%s : %s", "%pf", p); 3702 return NULL;
3699 /* remove ending quotes and new line since we will add one too */ 3703 /* remove ending quotes and new line since we will add one too */
3700 p = format + strlen(format) - 1; 3704 p = format + strlen(format) - 1;
3701 if (*p == '"') 3705 if (*p == '"')