public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@kernel.org>, Jiri Olsa <jolsa@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH 04/14] tools lib traceevent: Get rid of malloc_or_die() allocate_arg()
Date: Mon,  9 Dec 2013 14:34:01 +0900	[thread overview]
Message-ID: <1386567251-22751-5-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1386567251-22751-1-git-send-email-namhyung@kernel.org>

Also check return value and handle it.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/parse-filter.c | 59 +++++++++++++++++++++++++++----------
 1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 21d13a4f9a5f..35fac1fa376b 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -211,12 +211,7 @@ struct event_filter *pevent_filter_alloc(struct pevent *pevent)
 
 static struct filter_arg *allocate_arg(void)
 {
-	struct filter_arg *arg;
-
-	arg = malloc_or_die(sizeof(*arg));
-	memset(arg, 0, sizeof(*arg));
-
-	return arg;
+	return calloc(1, sizeof(struct filter_arg));
 }
 
 static void free_arg(struct filter_arg *arg)
@@ -359,6 +354,10 @@ create_arg_item(struct event_format *event, const char *token,
 	struct filter_arg *arg;
 
 	arg = allocate_arg();
+	if (arg == NULL) {
+		show_error(error_str, "failed to allocate filter arg");
+		return NULL;
+	}
 
 	switch (type) {
 
@@ -409,8 +408,10 @@ create_arg_op(enum filter_op_type btype)
 	struct filter_arg *arg;
 
 	arg = allocate_arg();
-	arg->type = FILTER_ARG_OP;
-	arg->op.type = btype;
+	if (arg) {
+		arg->type = FILTER_ARG_OP;
+		arg->op.type = btype;
+	}
 
 	return arg;
 }
@@ -421,8 +422,10 @@ create_arg_exp(enum filter_exp_type etype)
 	struct filter_arg *arg;
 
 	arg = allocate_arg();
-	arg->type = FILTER_ARG_EXP;
-	arg->op.type = etype;
+	if (arg) {
+		arg->type = FILTER_ARG_EXP;
+		arg->op.type = etype;
+	}
 
 	return arg;
 }
@@ -433,9 +436,11 @@ create_arg_cmp(enum filter_exp_type etype)
 	struct filter_arg *arg;
 
 	arg = allocate_arg();
-	/* Use NUM and change if necessary */
-	arg->type = FILTER_ARG_NUM;
-	arg->op.type = etype;
+	if (arg) {
+		/* Use NUM and change if necessary */
+		arg->type = FILTER_ARG_NUM;
+		arg->op.type = etype;
+	}
 
 	return arg;
 }
@@ -896,8 +901,10 @@ static struct filter_arg *collapse_tree(struct filter_arg *arg)
 	case FILTER_VAL_FALSE:
 		free_arg(arg);
 		arg = allocate_arg();
-		arg->type = FILTER_ARG_BOOLEAN;
-		arg->boolean.value = ret == FILTER_VAL_TRUE;
+		if (arg) {
+			arg->type = FILTER_ARG_BOOLEAN;
+			arg->boolean.value = ret == FILTER_VAL_TRUE;
+		}
 	}
 
 	return arg;
@@ -1044,6 +1051,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
 			switch (op_type) {
 			case OP_BOOL:
 				arg = create_arg_op(btype);
+				if (arg == NULL)
+					goto fail_alloc;
 				if (current_op)
 					ret = add_left(arg, current_op);
 				else
@@ -1054,6 +1063,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
 
 			case OP_NOT:
 				arg = create_arg_op(btype);
+				if (arg == NULL)
+					goto fail_alloc;
 				if (current_op)
 					ret = add_right(current_op, arg, error_str);
 				if (ret < 0)
@@ -1073,6 +1084,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
 					arg = create_arg_exp(etype);
 				else
 					arg = create_arg_cmp(ctype);
+				if (arg == NULL)
+					goto fail_alloc;
 
 				if (current_op)
 					ret = add_right(current_op, arg, error_str);
@@ -1106,11 +1119,16 @@ process_filter(struct event_format *event, struct filter_arg **parg,
 		current_op = current_exp;
 
 	current_op = collapse_tree(current_op);
+	if (current_op == NULL)
+		goto fail_alloc;
 
 	*parg = current_op;
 
 	return 0;
 
+ fail_alloc:
+	show_error(error_str, "failed to allocate filter arg");
+	goto fail;
  fail_print:
 	show_error(error_str, "Syntax error");
  fail:
@@ -1141,6 +1159,10 @@ process_event(struct event_format *event, const char *filter_str,
 	/* If parg is NULL, then make it into FALSE */
 	if (!*parg) {
 		*parg = allocate_arg();
+		if (*parg == NULL) {
+			show_error(error_str, "failed to allocate filter arg");
+			return -1;
+		}
 		(*parg)->type = FILTER_ARG_BOOLEAN;
 		(*parg)->boolean.value = FILTER_FALSE;
 	}
@@ -1164,6 +1186,10 @@ static int filter_event(struct event_filter *filter,
 	} else {
 		/* just add a TRUE arg */
 		arg = allocate_arg();
+		if (arg == NULL) {
+			show_error(error_str, "failed to allocate filter arg");
+			return -1;
+		}
 		arg->type = FILTER_ARG_BOOLEAN;
 		arg->boolean.value = FILTER_TRUE;
 	}
@@ -1399,6 +1425,9 @@ static int copy_filter_type(struct event_filter *filter,
 	if (strcmp(str, "TRUE") == 0 || strcmp(str, "FALSE") == 0) {
 		/* Add trivial event */
 		arg = allocate_arg();
+		if (arg == NULL)
+			return -1;
+
 		arg->type = FILTER_ARG_BOOLEAN;
 		if (strcmp(str, "TRUE") == 0)
 			arg->boolean.value = 1;
-- 
1.7.11.7


  parent reply	other threads:[~2013-12-09  5:37 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-09  5:33 [PATCHSET 00/14] tools lib traceevent: Get rid of *die() calls from parse-filter.c Namhyung Kim
2013-12-09  5:33 ` [PATCH 01/14] tools lib traceevent: Get rid of malloc_or_die() in show_error() Namhyung Kim
2013-12-09 18:30   ` Arnaldo Carvalho de Melo
2013-12-09 19:03     ` Steven Rostedt
2013-12-09 19:14       ` Arnaldo Carvalho de Melo
2013-12-09 19:23         ` Steven Rostedt
2013-12-10  2:03           ` Namhyung Kim
2013-12-10  2:14             ` Steven Rostedt
2013-12-10  5:01               ` Namhyung Kim
2013-12-10  5:30                 ` Namhyung Kim
2013-12-11  0:40                   ` Namhyung Kim
2013-12-11  1:55                     ` Steven Rostedt
2013-12-11  2:29                       ` Namhyung Kim
2013-12-12  1:10                         ` Steven Rostedt
2013-12-09  5:33 ` [PATCH 02/14] tools lib traceevent: Get rid of die in add_filter_type() Namhyung Kim
2013-12-09 10:44   ` Jiri Olsa
2013-12-10  0:32     ` Namhyung Kim
2013-12-09  5:34 ` [PATCH 03/14] tools lib traceevent: Get rid of malloc_or_die() in pevent_filter_alloc() Namhyung Kim
2013-12-11 11:05   ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-12-09  5:34 ` Namhyung Kim [this message]
2013-12-09 16:05   ` [PATCH 04/14] tools lib traceevent: Get rid of malloc_or_die() allocate_arg() Steven Rostedt
2013-12-10  1:21     ` Namhyung Kim
2013-12-10  2:08       ` Steven Rostedt
2013-12-09  5:34 ` [PATCH 05/14] tools lib traceevent: Get rid of malloc_or_die() in read_token() Namhyung Kim
2013-12-09  5:34 ` [PATCH 06/14] tools lib traceevent: Get rid of malloc_or_die() in find_event() Namhyung Kim
2013-12-09 11:03   ` Jiri Olsa
2013-12-09 16:27     ` Steven Rostedt
2013-12-10  0:48     ` Namhyung Kim
2013-12-09  5:34 ` [PATCH 07/14] tools lib traceevent: Get rid of malloc_or_die() in add_event() Namhyung Kim
2013-12-11 11:06   ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-12-09  5:34 ` [PATCH 08/14] tools lib traceevent: Get rid of die() in create_arg_item() Namhyung Kim
2013-12-11 11:06   ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-12-09  5:34 ` [PATCH 09/14] tools lib traceevent: Get rid of die() in add_right() Namhyung Kim
2013-12-09  6:28   ` Ilia Mirkin
2013-12-09  6:59     ` Namhyung Kim
2013-12-09 16:32       ` Steven Rostedt
2013-12-09 23:47         ` Namhyung Kim
2013-12-09  5:34 ` [PATCH 10/14] tools lib traceevent: Get rid of die() in reparent_op_arg() Namhyung Kim
2013-12-09  5:34 ` [PATCH 11/14] tools lib traceevent: Get rid of malloc_or_die() in pevent_filter_add_filter_str() Namhyung Kim
2013-12-11 11:06   ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-12-09  5:34 ` [PATCH 12/14] tools lib traceevent: Get rid of die() in pevent_filter_clear_trivial() Namhyung Kim
2013-12-11 11:06   ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-12-09  5:34 ` [PATCH 13/14] tools lib traceevent: Refactor test_filter() to get rid of die() Namhyung Kim
2013-12-09 16:19   ` Steven Rostedt
2013-12-10  1:48     ` Namhyung Kim
2013-12-09  5:34 ` [PATCH 14/14] tools lib traceevent: Get rid of die() in some string conversion funcitons Namhyung Kim
2013-12-09 16:24   ` Steven Rostedt
2013-12-10  1:50     ` Namhyung Kim
2013-12-09 10:47 ` [PATCHSET 00/14] tools lib traceevent: Get rid of *die() calls from parse-filter.c Jiri Olsa
2013-12-09 16:40   ` Steven Rostedt
2013-12-09 16:24 ` Steven Rostedt
2013-12-09 18:41   ` Arnaldo Carvalho de Melo
2013-12-10  0:34     ` Namhyung Kim

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=1386567251-22751-5-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --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