Commit 929a6bb7 authored by Javi Merino's avatar Javi Merino Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Factor out allocating and processing args

The sequence of allocating the print_arg field, calling process_arg()
and verifying that the next event delimiter is repeated twice in
process_hex() and will also be used for process_int_array().

Factor it out to a function to avoid writing the same code again and
again.
Signed-off-by: default avatarJavi Merino <javi.merino@arm.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1426875176-30244-2-git-send-email-javi.merino@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e6d7c91c
......@@ -2014,6 +2014,38 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
return EVENT_ERROR;
}
static int alloc_and_process_delim(struct event_format *event, char *next_token,
struct print_arg **print_arg)
{
struct print_arg *field;
enum event_type type;
char *token;
int ret = 0;
field = alloc_arg();
if (!field) {
do_warning_event(event, "%s: not enough memory!", __func__);
errno = ENOMEM;
return -1;
}
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, next_token)) {
errno = EINVAL;
ret = -1;
free_arg(field);
goto out_free_token;
}
*print_arg = field;
out_free_token:
free_token(token);
return ret;
}
static char *arg_eval (struct print_arg *arg);
static unsigned long long
......@@ -2486,49 +2518,20 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
static enum event_type
process_hex(struct event_format *event, struct print_arg *arg, char **tok)
{
struct print_arg *field;
enum event_type type;
char *token = NULL;
memset(arg, 0, sizeof(*arg));
arg->type = PRINT_HEX;
field = alloc_arg();
if (!field) {
do_warning_event(event, "%s: not enough memory!", __func__);
goto out_free;
}
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ","))
goto out_free;
arg->hex.field = field;
free_token(token);
field = alloc_arg();
if (!field) {
do_warning_event(event, "%s: not enough memory!", __func__);
*tok = NULL;
return EVENT_ERROR;
}
type = process_arg(event, field, &token);
if (alloc_and_process_delim(event, ",", &arg->hex.field))
goto out;
if (test_type_token(type, token, EVENT_DELIM, ")"))
goto out_free;
if (alloc_and_process_delim(event, ")", &arg->hex.size))
goto free_field;
arg->hex.size = field;
return read_token_item(tok);
free_token(token);
type = read_token_item(tok);
return type;
out_free:
free_arg(field);
free_token(token);
free_field:
free_arg(arg->hex.field);
out:
*tok = NULL;
return EVENT_ERROR;
}
......
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