tools lib traceevent: Use asprintf were applicable

Replacing the equivalent open coded malloc + sprintf bits.
Reviewed-by: default avatarNamhyung 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3ce711a6
...@@ -827,9 +827,9 @@ static enum event_type __read_token(char **tok) ...@@ -827,9 +827,9 @@ static enum event_type __read_token(char **tok)
switch (type) { switch (type) {
case EVENT_NEWLINE: case EVENT_NEWLINE:
case EVENT_DELIM: case EVENT_DELIM:
*tok = malloc_or_die(2); if (asprintf(tok, "%c", ch) < 0)
(*tok)[0] = ch; return EVENT_ERROR;
(*tok)[1] = 0;
return type; return type;
case EVENT_OP: case EVENT_OP:
...@@ -2777,10 +2777,8 @@ static int event_read_print(struct event_format *event) ...@@ -2777,10 +2777,8 @@ static int event_read_print(struct event_format *event)
if (type == EVENT_DQUOTE) { if (type == EVENT_DQUOTE) {
char *cat; char *cat;
cat = malloc_or_die(strlen(event->print_fmt.format) + if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
strlen(token) + 1); goto fail;
strcpy(cat, event->print_fmt.format);
strcat(cat, token);
free_token(token); free_token(token);
free_token(event->print_fmt.format); free_token(event->print_fmt.format);
event->print_fmt.format = NULL; event->print_fmt.format = NULL;
...@@ -3524,6 +3522,18 @@ process_defined_func(struct trace_seq *s, void *data, int size, ...@@ -3524,6 +3522,18 @@ process_defined_func(struct trace_seq *s, void *data, int size,
return ret; return ret;
} }
static void free_args(struct print_arg *args)
{
struct print_arg *next;
while (args) {
next = args->next;
free_arg(args);
args = next;
}
}
static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event) static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
{ {
struct pevent *pevent = event->pevent; struct pevent *pevent = event->pevent;
...@@ -3559,8 +3569,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc ...@@ -3559,8 +3569,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
next = &arg->next; next = &arg->next;
arg->type = PRINT_ATOM; arg->type = PRINT_ATOM;
arg->atom.atom = malloc_or_die(32);
sprintf(arg->atom.atom, "%lld", ip); if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
goto out_free;
/* skip the first "%pf : " */ /* skip the first "%pf : " */
for (ptr = fmt + 6, bptr = data + field->offset; 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,8 +3628,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
arg = alloc_arg(); arg = alloc_arg();
arg->next = NULL; arg->next = NULL;
arg->type = PRINT_ATOM; arg->type = PRINT_ATOM;
arg->atom.atom = malloc_or_die(32); if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
sprintf(arg->atom.atom, "%lld", val); free(arg);
goto out_free;
}
*next = arg; *next = arg;
next = &arg->next; next = &arg->next;
/* /*
...@@ -3646,18 +3659,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc ...@@ -3646,18 +3659,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
} }
return args; return args;
}
static void free_args(struct print_arg *args)
{
struct print_arg *next;
while (args) {
next = args->next;
free_arg(args); out_free:
args = next; free_args(args);
} return NULL;
} }
static char * static char *
...@@ -3684,9 +3689,8 @@ get_bprint_format(void *data, int size __maybe_unused, ...@@ -3684,9 +3689,8 @@ get_bprint_format(void *data, int size __maybe_unused,
printk = find_printk(pevent, addr); printk = find_printk(pevent, addr);
if (!printk) { if (!printk) {
format = malloc_or_die(45); if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0)
sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n", return NULL;
addr);
return format; return format;
} }
...@@ -3694,8 +3698,8 @@ get_bprint_format(void *data, int size __maybe_unused, ...@@ -3694,8 +3698,8 @@ get_bprint_format(void *data, int size __maybe_unused,
/* Remove any quotes. */ /* Remove any quotes. */
if (*p == '"') if (*p == '"')
p++; p++;
format = malloc_or_die(strlen(p) + 10); if (asprintf(&format, "%s : %s", "%pf", p) < 0)
sprintf(format, "%s : %s", "%pf", p); return NULL;
/* remove ending quotes and new line since we will add one too */ /* remove ending quotes and new line since we will add one too */
p = format + strlen(format) - 1; p = format + strlen(format) - 1;
if (*p == '"') if (*p == '"')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment