aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorJavi Merino <javi.merino@arm.com>2015-03-20 14:12:55 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-03-24 11:07:05 -0400
commit929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a (patch)
tree01b5ec713cd8bdfd2ce1c7983bf21d8d87761a85 /tools/lib
parente6d7c91c8c5ea532584056f3e8bf1643310c8ef7 (diff)
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: Javi Merino <javi.merino@arm.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Steven 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.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/traceevent/event-parse.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index d7c37a7d9255..8e5e4f6137bb 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -2014,6 +2014,38 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
2014 return EVENT_ERROR; 2014 return EVENT_ERROR;
2015} 2015}
2016 2016
2017static int alloc_and_process_delim(struct event_format *event, char *next_token,
2018 struct print_arg **print_arg)
2019{
2020 struct print_arg *field;
2021 enum event_type type;
2022 char *token;
2023 int ret = 0;
2024
2025 field = alloc_arg();
2026 if (!field) {
2027 do_warning_event(event, "%s: not enough memory!", __func__);
2028 errno = ENOMEM;
2029 return -1;
2030 }
2031
2032 type = process_arg(event, field, &token);
2033
2034 if (test_type_token(type, token, EVENT_DELIM, next_token)) {
2035 errno = EINVAL;
2036 ret = -1;
2037 free_arg(field);
2038 goto out_free_token;
2039 }
2040
2041 *print_arg = field;
2042
2043out_free_token:
2044 free_token(token);
2045
2046 return ret;
2047}
2048
2017static char *arg_eval (struct print_arg *arg); 2049static char *arg_eval (struct print_arg *arg);
2018 2050
2019static unsigned long long 2051static unsigned long long
@@ -2486,49 +2518,20 @@ out_free:
2486static enum event_type 2518static enum event_type
2487process_hex(struct event_format *event, struct print_arg *arg, char **tok) 2519process_hex(struct event_format *event, struct print_arg *arg, char **tok)
2488{ 2520{
2489 struct print_arg *field;
2490 enum event_type type;
2491 char *token = NULL;
2492
2493 memset(arg, 0, sizeof(*arg)); 2521 memset(arg, 0, sizeof(*arg));
2494 arg->type = PRINT_HEX; 2522 arg->type = PRINT_HEX;
2495 2523
2496 field = alloc_arg(); 2524 if (alloc_and_process_delim(event, ",", &arg->hex.field))
2497 if (!field) { 2525 goto out;
2498 do_warning_event(event, "%s: not enough memory!", __func__);
2499 goto out_free;
2500 }
2501
2502 type = process_arg(event, field, &token);
2503
2504 if (test_type_token(type, token, EVENT_DELIM, ","))
2505 goto out_free;
2506
2507 arg->hex.field = field;
2508
2509 free_token(token);
2510
2511 field = alloc_arg();
2512 if (!field) {
2513 do_warning_event(event, "%s: not enough memory!", __func__);
2514 *tok = NULL;
2515 return EVENT_ERROR;
2516 }
2517
2518 type = process_arg(event, field, &token);
2519
2520 if (test_type_token(type, token, EVENT_DELIM, ")"))
2521 goto out_free;
2522 2526
2523 arg->hex.size = field; 2527 if (alloc_and_process_delim(event, ")", &arg->hex.size))
2528 goto free_field;
2524 2529
2525 free_token(token); 2530 return read_token_item(tok);
2526 type = read_token_item(tok);
2527 return type;
2528 2531
2529 out_free: 2532free_field:
2530 free_arg(field); 2533 free_arg(arg->hex.field);
2531 free_token(token); 2534out:
2532 *tok = NULL; 2535 *tok = NULL;
2533 return EVENT_ERROR; 2536 return EVENT_ERROR;
2534} 2537}