linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung.kim@lge.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 14/20] tools lib traceevent: Get rid of die() in add_right()
Date: Fri, 13 Dec 2013 12:12:00 -0300	[thread overview]
Message-ID: <1386947526-7118-15-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1386947526-7118-1-git-send-email-acme@infradead.org>

From: Namhyung Kim <namhyung@kernel.org>

Refactor it to return appropriate pevent_errno value.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386833777-3790-7-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/event-parse.h  |  8 +++++++-
 tools/lib/traceevent/parse-filter.c | 34 +++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index abdfd3c606ed..89e4dfd40db6 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -358,7 +358,13 @@ enum pevent_flag {
 	_PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
 	_PE(INVALID_ARG_TYPE,	"invalid argument type"),		      \
 	_PE(INVALID_EVENT_NAME,	"invalid event name"),			      \
-	_PE(EVENT_NOT_FOUND,	"No event found")
+	_PE(EVENT_NOT_FOUND,	"no event found"),			      \
+	_PE(SYNTAX_ERROR,	"syntax error"),			      \
+	_PE(ILLEGAL_RVALUE,	"illegal rvalue"),			      \
+	_PE(ILLEGAL_LVALUE,	"illegal lvalue for string comparison"),      \
+	_PE(INVALID_REGEX,	"regex did not compute"),		      \
+	_PE(ILLEGAL_STRING_CMP,	"illegal comparison for string"), 	      \
+	_PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer")
 
 #undef _PE
 #define _PE(__code, __str) PEVENT_ERRNO__ ## __code
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index a0ab040e8f71..c08ce594cabe 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -473,8 +473,8 @@ create_arg_cmp(enum filter_exp_type etype)
 	return arg;
 }
 
-static int add_right(struct filter_arg *op, struct filter_arg *arg,
-		     char **error_str)
+static enum pevent_errno
+add_right(struct filter_arg *op, struct filter_arg *arg, char **error_str)
 {
 	struct filter_arg *left;
 	char *str;
@@ -505,9 +505,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 		case FILTER_ARG_FIELD:
 			break;
 		default:
-			show_error(error_str,
-				   "Illegal rvalue");
-			return -1;
+			show_error(error_str, "Illegal rvalue");
+			return PEVENT_ERRNO__ILLEGAL_RVALUE;
 		}
 
 		/*
@@ -554,7 +553,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 			if (left->type != FILTER_ARG_FIELD) {
 				show_error(error_str,
 					   "Illegal lvalue for string comparison");
-				return -1;
+				return PEVENT_ERRNO__ILLEGAL_LVALUE;
 			}
 
 			/* Make sure this is a valid string compare */
@@ -573,25 +572,31 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 					show_error(error_str,
 						   "RegEx '%s' did not compute",
 						   str);
-					return -1;
+					return PEVENT_ERRNO__INVALID_REGEX;
 				}
 				break;
 			default:
 				show_error(error_str,
 					   "Illegal comparison for string");
-				return -1;
+				return PEVENT_ERRNO__ILLEGAL_STRING_CMP;
 			}
 
 			op->type = FILTER_ARG_STR;
 			op->str.type = op_type;
 			op->str.field = left->field.field;
 			op->str.val = strdup(str);
-			if (!op->str.val)
-				die("malloc string");
+			if (!op->str.val) {
+				show_error(error_str, "Failed to allocate string filter");
+				return PEVENT_ERRNO__MEM_ALLOC_FAILED;
+			}
 			/*
 			 * Need a buffer to copy data for tests
 			 */
-			op->str.buffer = malloc_or_die(op->str.field->size + 1);
+			op->str.buffer = malloc(op->str.field->size + 1);
+			if (!op->str.buffer) {
+				show_error(error_str, "Failed to allocate string filter");
+				return PEVENT_ERRNO__MEM_ALLOC_FAILED;
+			}
 			/* Null terminate this buffer */
 			op->str.buffer[op->str.field->size] = 0;
 
@@ -609,7 +614,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 			case FILTER_CMP_NOT_REGEX:
 				show_error(error_str,
 					   "Op not allowed with integers");
-				return -1;
+				return PEVENT_ERRNO__ILLEGAL_INTEGER_CMP;
 
 			default:
 				break;
@@ -629,9 +634,8 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 	return 0;
 
  out_fail:
-	show_error(error_str,
-		   "Syntax error");
-	return -1;
+	show_error(error_str, "Syntax error");
+	return PEVENT_ERRNO__SYNTAX_ERROR;
 }
 
 static struct filter_arg *
-- 
1.8.1.4


  parent reply	other threads:[~2013-12-13 15:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-13 15:11 [GIT PULL 00/20] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 01/20] tools lib symbol: Start carving out symbol parsing routines from perf Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 02/20] perf tools: Add perf_event_paranoid() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 03/20] perf header: Allow header->data_offset to be predetermined Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 04/20] perf evlist: Add can_select_event() method Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 05/20] perf tools: Move mem_bswap32/64 to util.c Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 06/20] perf tools: Fix inverted error verification bug in thread__fork Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 07/20] perf evlist: Add perf_evlist__to_front() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 08/20] perf completion: Complete 'perf kvm' Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 09/20] tools lib traceevent: Get rid of malloc_or_die() in show_error() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 10/20] tools lib traceevent: Get rid of die in add_filter_type() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 11/20] tools lib traceevent: Get rid of malloc_or_die() allocate_arg() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 12/20] tools lib traceevent: Get rid of malloc_or_die() in read_token() Arnaldo Carvalho de Melo
2013-12-13 15:11 ` [PATCH 13/20] tools lib traceevent: Get rid of malloc_or_die() in find_event() Arnaldo Carvalho de Melo
2013-12-13 15:12 ` Arnaldo Carvalho de Melo [this message]
2013-12-13 15:12 ` [PATCH 15/20] tools lib traceevent: Make add_left() return pevent_errno Arnaldo Carvalho de Melo
2013-12-13 15:12 ` [PATCH 16/20] tools lib traceevent: Get rid of die() in reparent_op_arg() Arnaldo Carvalho de Melo
2013-12-13 15:12 ` [PATCH 17/20] tools lib traceevent: Refactor create_arg_item() Arnaldo Carvalho de Melo
2013-12-13 15:12 ` [PATCH 18/20] tools lib traceevent: Refactor process_filter() Arnaldo Carvalho de Melo
2013-12-13 15:12 ` [PATCH 19/20] tools lib traceevent: Make pevent_filter_add_filter_str() return pevent_errno Arnaldo Carvalho de Melo
2013-12-13 15:12 ` [PATCH 20/20] tools lib traceevent: Refactor pevent_filter_match() to get rid of die() Arnaldo Carvalho de Melo
2013-12-16 13:54 ` [GIT PULL 00/20] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386947526-7118-15-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).