From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754101AbbCXQcC (ORCPT ); Tue, 24 Mar 2015 12:32:02 -0400 Received: from terminus.zytor.com ([198.137.202.10]:56826 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752338AbbCXQb6 (ORCPT ); Tue, 24 Mar 2015 12:31:58 -0400 Date: Tue, 24 Mar 2015 09:31:33 -0700 From: tip-bot for Javi Merino Message-ID: Cc: acme@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com, namhyung@kernel.org, javi.merino@arm.com, jolsa@redhat.com, tglx@linutronix.de, mingo@kernel.org, rostedt@goodmis.org Reply-To: linux-kernel@vger.kernel.org, acme@redhat.com, namhyung@kernel.org, hpa@zytor.com, javi.merino@arm.com, mingo@kernel.org, rostedt@goodmis.org, jolsa@redhat.com, tglx@linutronix.de In-Reply-To: <1426875176-30244-2-git-send-email-javi.merino@arm.com> References: <1426875176-30244-2-git-send-email-javi.merino@arm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] tools lib traceevent: Factor out allocating and processing args Git-Commit-ID: 929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a Gitweb: http://git.kernel.org/tip/929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a Author: Javi Merino AuthorDate: Fri, 20 Mar 2015 18:12:55 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 24 Mar 2015 12:07:05 -0300 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 Acked-by: Namhyung Kim Acked-by: Steven Rostedt Cc: Jiri Olsa Link: http://lkml.kernel.org/r/1426875176-30244-2-git-send-email-javi.merino@arm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/traceevent/event-parse.c | 77 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index d7c37a7..8e5e4f6 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, 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 @@ out_free: 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 (test_type_token(type, token, EVENT_DELIM, ")")) - goto out_free; + if (alloc_and_process_delim(event, ",", &arg->hex.field)) + goto out; - arg->hex.size = field; + if (alloc_and_process_delim(event, ")", &arg->hex.size)) + goto free_field; - free_token(token); - type = read_token_item(tok); - return type; + return read_token_item(tok); - out_free: - free_arg(field); - free_token(token); +free_field: + free_arg(arg->hex.field); +out: *tok = NULL; return EVENT_ERROR; }