linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2
@ 2012-04-23  4:58 Namhyung Kim
  2012-04-23  4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
                   ` (11 more replies)
  0 siblings, 12 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

Hi,

This is the second part of my libparsevent cleanups. The patches are
based on my previous patch set [1].

Any comments are welcome.
Thanks.

[1] https://lkml.org/lkml/2012/4/8/177


Namhyung Kim (11):
  parse-events: Free flag/sym field on failure path
  parse-events: Fix freeing arg on process_dynamic_array()
  parse-events: Get rid of handling concatenation on event_read_print
  parse-events: Remove unused arg->dynarray.index
  parse-events: Use proper function parameter type
  parse-events: Pass string type argument to args
  parse-events: Do not call add_event() again if allocation failed
  parse-events: Fix some comments
  parse-filter: Check result of malloc() during reading token
  parse-filter: Fix signature of create_arg_item()
  parse-filter: Check return value of arg_to_str()

 parse-events.c |   62 ++++++++++++++++++++++----------------------------------
 parse-events.h |    1 -
 parse-filter.c |   22 ++++++++++++++------
 3 files changed, 40 insertions(+), 45 deletions(-)

-- 
1.7.10


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH 01/11] parse-events: Free flag/sym field on failure path
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 16:21   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array() Namhyung Kim
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

If parsing flag/sym field failed after allocating it, it
should be freed.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index bd078ba..81e6581 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -2166,10 +2166,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 
 		value = arg_eval(arg);
 		if (value == NULL)
-			goto out_free;
+			goto out_free_field;
 		field->value = strdup(value);
 		if (field->value == NULL)
-			goto out_free;
+			goto out_free_field;
 
 		free_arg(arg);
 		arg = alloc_arg();
@@ -2177,14 +2177,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 		free_token(token);
 		type = process_arg(event, arg, &token);
 		if (test_type_token(type, token, EVENT_OP, "}"))
-			goto out_free;
+			goto out_free_field_value;
 
 		value = arg_eval(arg);
 		if (value == NULL)
-			goto out_free;
+			goto out_free_field_value;
 		field->str = strdup(value);
 		if (field->str == NULL)
-			goto out_free;
+			goto out_free_field_value;
 		free_arg(arg);
 		arg = NULL;
 
@@ -2198,6 +2198,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 	*tok = token;
 	return type;
 
+out_free_field_value:
+	free(field->value);
+out_free_field:
+	free(field);
 out_free:
 	free_arg(arg);
 	free_token(token);
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array()
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
  2012-04-23  4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 16:34   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print Namhyung Kim
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The @arg paremeter should not be freed inside of process_XXX(),
because it'd be freed from the caller of process_arg(). We can
free it only after it was reused for local usage.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index 81e6581..0cd79c5 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -2330,17 +2330,18 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
 	arg = alloc_arg();
 	type = process_arg(event, arg, &token);
 	if (type == EVENT_ERROR)
-		goto out_free;
+		goto out_free_arg;
 
 	if (!test_type_token(type, token, EVENT_OP, "]"))
-		goto out_free;
+		goto out_free_arg;
 
 	free_token(token);
 	type = read_token_item(tok);
 	return type;
 
+ out_free_arg:
+	free_arg(arg);
  out_free:
-	free(arg);
 	free_token(token);
 	*tok = NULL;
 	return EVENT_ERROR;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
  2012-04-23  4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
  2012-04-23  4:58 ` [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array() Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 16:33   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 04/11] parse-events: Remove unused arg->dynarray.index Namhyung Kim
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The concatenation of subsequent DQUOTE'd strings is handled
by __read_token() already.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |   16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index 0cd79c5..b4ae313 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -2695,7 +2695,6 @@ static int event_read_print(struct event_format *event)
 	if (read_expect_type(EVENT_DQUOTE, &token) < 0)
 		goto fail;
 
- concat:
 	event->print_fmt.format = token;
 	event->print_fmt.args = NULL;
 
@@ -2705,21 +2704,6 @@ static int event_read_print(struct event_format *event)
 	if (type == EVENT_NONE)
 		return 0;
 
-	/* Handle concatenation of print lines */
-	if (type == EVENT_DQUOTE) {
-		char *cat;
-
-		cat = malloc_or_die(strlen(event->print_fmt.format) +
-				    strlen(token) + 1);
-		strcpy(cat, event->print_fmt.format);
-		strcat(cat, token);
-		free_token(token);
-		free_token(event->print_fmt.format);
-		event->print_fmt.format = NULL;
-		token = cat;
-		goto concat;
-	}
-			     
 	if (test_type_token(type, token, EVENT_DELIM, ","))
 		goto fail;
 
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 04/11] parse-events: Remove unused arg->dynarray.index
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (2 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:35   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 05/11] parse-events: Use proper function parameter type Namhyung Kim
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

It seems index field of struct print_arg_dynarray is not used.
Let's remove it.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    4 ----
 parse-events.h |    1 -
 2 files changed, 5 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index b4ae313..3e5ac44 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -706,9 +706,6 @@ static void free_arg(struct print_arg *arg)
 	case PRINT_BSTRING:
 		free(arg->string.string);
 		break;
-	case PRINT_DYNAMIC_ARRAY:
-		free(arg->dynarray.index);
-		break;
 	case PRINT_OP:
 		free(arg->op.op);
 		free_arg(arg->op.left);
@@ -2315,7 +2312,6 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
 		goto out_free;
 
 	arg->dynarray.field = field;
-	arg->dynarray.index = 0;
 
 	if (read_expected(EVENT_DELIM, ")") < 0)
 		goto out_free;
diff --git a/parse-events.h b/parse-events.h
index 67e7886..960e598 100644
--- a/parse-events.h
+++ b/parse-events.h
@@ -226,7 +226,6 @@ struct print_arg_symbol {
 
 struct print_arg_dynarray {
 	struct format_field	*field;
-	struct print_arg	*index;
 };
 
 struct print_arg;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 05/11] parse-events: Use proper function parameter type
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (3 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 04/11] parse-events: Remove unused arg->dynarray.index Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:38   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The param needs to be updated when setting args up so that
the loop in process_defined_func() can see the correct
param->type for the farg.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/parse-events.c b/parse-events.c
index 3e5ac44..b7c81d8 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -3396,6 +3396,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
 			break;
 		}
 		farg = farg->next;
+		param = param->next;
 	}
 
 	ret = (*func_handle->func)(s, args);
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 06/11] parse-events: Pass string type argument to args
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (4 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 05/11] parse-events: Use proper function parameter type Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:41   ` Steven Rostedt
  2012-07-06 11:16   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  2012-04-23  4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
                   ` (5 subsequent siblings)
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

It seems PEVENT_FUNC_ARG_STRING missed passing the allocated
string to the args array. Fix it.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/parse-events.c b/parse-events.c
index b7c81d8..3b39923 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -3384,6 +3384,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
 			if (!string->str)
 				die("malloc str");
 
+			args[i] = (unsigned long long)string->str;
 			strings = string;
 			trace_seq_destroy(&str);
 			break;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (5 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:43   ` Steven Rostedt
  2012-07-06 11:17   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  2012-04-23  4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
                   ` (4 subsequent siblings)
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

When memory allocation for the field name is failed, do not
goto event_failed since we added the event already.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parse-events.c b/parse-events.c
index 3b39923..52cf331 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -4637,7 +4637,8 @@ int pevent_parse_event(struct pevent *pevent,
 			arg->field.name = strdup(field->name);
 			if (!arg->field.name) {
 				do_warning("failed to allocate field name");
-				goto event_failed;
+				event->flags |= EVENT_FL_FAILED;
+				return -1;
 			}
 			arg->field.field = field;
 		}
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 08/11] parse-events: Fix some comments
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (6 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:47   ` Steven Rostedt
  2012-07-06 11:18   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  2012-04-23  4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
                   ` (3 subsequent siblings)
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

Update and add missing argument descriptions and fix some typo
on function comments.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index 52cf331..0d785c2 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -3920,8 +3920,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
  * pevent_data_lat_fmt - parse the data for the latency format
  * @pevent: a handle to the pevent
  * @s: the trace_seq to write to
- * @data: the raw data to read from
- * @size: currently unused.
+ * @record: the record to read from
  *
  * This parses out the Latency format (interrupts disabled,
  * need rescheduling, in hard/soft interrupt, preempt count
@@ -4056,10 +4055,7 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid)
  * pevent_data_comm_from_pid - parse the data into the print format
  * @s: the trace_seq to write to
  * @event: the handle to the event
- * @cpu: the cpu the event was recorded on
- * @data: the raw data
- * @size: the size of the raw data
- * @nsecs: the timestamp of the event
+ * @record: the record to read from
  *
  * This parses the raw @data using the given @event information and
  * writes the print format into the trace_seq.
@@ -4811,7 +4807,7 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
  * @record: The record with the field name.
  * @err: print default error if failed.
  *
- * Returns: 0 on success, -1 field not fould, or 1 if buffer is full.
+ * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
  */
 int pevent_print_num_field(struct trace_seq *s, const char *fmt,
 			   struct event_format *event, const char *name,
@@ -4853,11 +4849,12 @@ static void free_func_handle(struct pevent_function_handler *func)
  * pevent_register_print_function - register a helper function
  * @pevent: the handle to the pevent
  * @func: the function to process the helper function
+ * @ret_type: the return type of the helper function
  * @name: the name of the helper function
  * @parameters: A list of enum pevent_func_arg_type
  *
  * Some events may have helper functions in the print format arguments.
- * This allows a plugin to dynmically create a way to process one
+ * This allows a plugin to dynamically create a way to process one
  * of these functions.
  *
  * The @parameters is a variable list of pevent_func_arg_type enums that
@@ -4928,12 +4925,13 @@ int pevent_register_print_function(struct pevent *pevent,
 }
 
 /**
- * pevent_register_event_handle - register a way to parse an event
+ * pevent_register_event_handler - register a way to parse an event
  * @pevent: the handle to the pevent
  * @id: the id of the event to register
  * @sys_name: the system name the event belongs to
  * @event_name: the name of the event
  * @func: the function to call to parse the event information
+ * @context: the data to be passed to @func
  *
  * This function allows a developer to override the parsing of
  * a given event. If for some reason the default print format
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 09/11] parse-filter: Check result of malloc() during reading token
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (7 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:48   ` Steven Rostedt
  2012-07-06 11:19   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  2012-04-23  4:58 ` [PATCH 10/11] parse-filter: Fix signature of create_arg_item() Namhyung Kim
                   ` (2 subsequent siblings)
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The malloc can fail so the return value should be checked.
For now, just use malloc_or_die().

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-filter.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parse-filter.c b/parse-filter.c
index bc62f1f..0e6c0b1 100644
--- a/parse-filter.c
+++ b/parse-filter.c
@@ -96,7 +96,7 @@ static enum event_type read_token(char **tok)
 	    (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) &&
 	    pevent_peek_char() == '~') {
 		/* append it */
-		*tok = malloc(3);
+		*tok = malloc_or_die(3);
 		sprintf(*tok, "%c%c", *token, '~');
 		free_token(token);
 		/* Now remove the '~' from the buffer */
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 10/11] parse-filter: Fix signature of create_arg_item()
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (8 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:57   ` Steven Rostedt
  2012-04-23  4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
  2012-04-24  1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
  11 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The @type should be a type of enum event_type not enum
filter_arg_type. This fixes following warning:

 $ make
  COMPILE FPIC           parse-events.o
  COMPILE FPIC           parse-filter.o
/home/namhyung/project/trace-cmd/parse-filter.c: In function ‘create_arg_item’:
/home/namhyung/project/trace-cmd/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare]
/home/namhyung/project/trace-cmd/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]
  BUILD STATIC LIB       libparsevent.a
  BUILD STATIC LIB       libtracecmd.a
  BUILD                  trace-cmd
/usr/bin/make -C /home/namhyung/project/trace-cmd/Documentation all
make[1]: Nothing to be done for `all'.
Note: to build the gui, type "make gui"

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-filter.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/parse-filter.c b/parse-filter.c
index 0e6c0b1..fa6e6a2 100644
--- a/parse-filter.c
+++ b/parse-filter.c
@@ -325,9 +325,8 @@ static void free_events(struct event_list *events)
 }
 
 static struct filter_arg *
-create_arg_item(struct event_format *event,
-		const char *token, enum filter_arg_type type,
-		char **error_str)
+create_arg_item(struct event_format *event, const char *token,
+		enum event_type type, char **error_str)
 {
 	struct format_field *field;
 	struct filter_arg *arg;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 11/11] parse-filter: Check return value of arg_to_str()
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (9 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 10/11] parse-filter: Fix signature of create_arg_item() Namhyung Kim
@ 2012-04-23  4:58 ` Namhyung Kim
  2012-04-23 18:59   ` Steven Rostedt
  2012-07-06 11:20   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  2012-04-24  1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-23  4:58 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker
  Cc: Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

The arg_to_str() can fail so we should handle that case properly.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-filter.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/parse-filter.c b/parse-filter.c
index fa6e6a2..d09fbd2 100644
--- a/parse-filter.c
+++ b/parse-filter.c
@@ -2026,11 +2026,13 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
 	char *lstr;
 	char *rstr;
 	char *op;
-	char *str;
+	char *str = NULL;
 	int len;
 
 	lstr = arg_to_str(filter, arg->exp.left);
 	rstr = arg_to_str(filter, arg->exp.right);
+	if (!lstr || !rstr)
+		goto out;
 
 	switch (arg->exp.type) {
 	case FILTER_EXP_ADD:
@@ -2070,6 +2072,7 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
 	len = strlen(op) + strlen(lstr) + strlen(rstr) + 4;
 	str = malloc_or_die(len);
 	snprintf(str, len, "%s %s %s", lstr, op, rstr);
+out:
 	free(lstr);
 	free(rstr);
 
@@ -2086,6 +2089,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
 
 	lstr = arg_to_str(filter, arg->num.left);
 	rstr = arg_to_str(filter, arg->num.right);
+	if (!lstr || !rstr)
+		goto out;
 
 	switch (arg->num.type) {
 	case FILTER_CMP_EQ:
@@ -2122,6 +2127,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
 		break;
 	}
 
+out:
 	free(lstr);
 	free(rstr);
 	return str;
@@ -2272,7 +2278,12 @@ int pevent_filter_compare(struct event_filter *filter1, struct event_filter *fil
 		/* The best way to compare complex filters is with strings */
 		str1 = arg_to_str(filter1, filter_type1->filter);
 		str2 = arg_to_str(filter2, filter_type2->filter);
-		result = strcmp(str1, str2) != 0;
+		if (str1 && str2)
+			result = strcmp(str1, str2) != 0;
+		else
+			/* bail out if allocation fails */
+			result = 1;
+
 		free(str1);
 		free(str2);
 		if (result)
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH 01/11] parse-events: Free flag/sym field on failure path
  2012-04-23  4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
@ 2012-04-23 16:21   ` Steven Rostedt
  2012-04-24  0:05     ` Namhyung Kim
  0 siblings, 1 reply; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 16:21 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> If parsing flag/sym field failed after allocating it, it
> should be freed.
> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-events.c |   14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/parse-events.c b/parse-events.c
> index bd078ba..81e6581 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -2166,10 +2166,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  
>  		value = arg_eval(arg);
>  		if (value == NULL)
> -			goto out_free;
> +			goto out_free_field;

Instead of adding more goto's what, before the first goto "out_free"
add:

	field = NULL;

and since the field is allocated and also memset to zero, we could do in
the out_free:

	if (field) {
		free(field->value);
		free(field);
	}

I think that would be cleaner.

-- Steve

>  		field->value = strdup(value);
>  		if (field->value == NULL)
> -			goto out_free;
> +			goto out_free_field;
>  
>  		free_arg(arg);
>  		arg = alloc_arg();
> @@ -2177,14 +2177,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  		free_token(token);
>  		type = process_arg(event, arg, &token);
>  		if (test_type_token(type, token, EVENT_OP, "}"))
> -			goto out_free;
> +			goto out_free_field_value;
>  
>  		value = arg_eval(arg);
>  		if (value == NULL)
> -			goto out_free;
> +			goto out_free_field_value;
>  		field->str = strdup(value);
>  		if (field->str == NULL)
> -			goto out_free;
> +			goto out_free_field_value;
>  		free_arg(arg);
>  		arg = NULL;
>  
> @@ -2198,6 +2198,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>  	*tok = token;
>  	return type;
>  
> +out_free_field_value:
> +	free(field->value);
> +out_free_field:
> +	free(field);
>  out_free:
>  	free_arg(arg);
>  	free_token(token);



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print
  2012-04-23  4:58 ` [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print Namhyung Kim
@ 2012-04-23 16:33   ` Steven Rostedt
  2012-04-24  0:09     ` Namhyung Kim
  0 siblings, 1 reply; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 16:33 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The concatenation of subsequent DQUOTE'd strings is handled
> by __read_token() already.
> 

You missed the point of this concat. It's not connecting "xxx" it is
connecting "xxx" "yyy" into "xxxyyy", as some events do this.

-- Steve

> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-events.c |   16 ----------------
>  1 file changed, 16 deletions(-)
> 
> diff --git a/parse-events.c b/parse-events.c
> index 0cd79c5..b4ae313 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -2695,7 +2695,6 @@ static int event_read_print(struct event_format *event)
>  	if (read_expect_type(EVENT_DQUOTE, &token) < 0)
>  		goto fail;
>  
> - concat:
>  	event->print_fmt.format = token;
>  	event->print_fmt.args = NULL;
>  
> @@ -2705,21 +2704,6 @@ static int event_read_print(struct event_format *event)
>  	if (type == EVENT_NONE)
>  		return 0;
>  
> -	/* Handle concatenation of print lines */
> -	if (type == EVENT_DQUOTE) {
> -		char *cat;
> -
> -		cat = malloc_or_die(strlen(event->print_fmt.format) +
> -				    strlen(token) + 1);
> -		strcpy(cat, event->print_fmt.format);
> -		strcat(cat, token);
> -		free_token(token);
> -		free_token(event->print_fmt.format);
> -		event->print_fmt.format = NULL;
> -		token = cat;
> -		goto concat;
> -	}
> -			     
>  	if (test_type_token(type, token, EVENT_DELIM, ","))
>  		goto fail;
>  



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array()
  2012-04-23  4:58 ` [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array() Namhyung Kim
@ 2012-04-23 16:34   ` Steven Rostedt
  0 siblings, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 16:34 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The @arg paremeter should not be freed inside of process_XXX(),
> because it'd be freed from the caller of process_arg(). We can
> free it only after it was reused for local usage.
> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>

Applied, thanks!

-- Steve



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 04/11] parse-events: Remove unused arg->dynarray.index
  2012-04-23  4:58 ` [PATCH 04/11] parse-events: Remove unused arg->dynarray.index Namhyung Kim
@ 2012-04-23 18:35   ` Steven Rostedt
  0 siblings, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:35 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> It seems index field of struct print_arg_dynarray is not used.
> Let's remove it.

Actually, the "non-use" looks like a bug. Where it is set to 0 (it
should be set to NULL), an 'arg' is allocated, but it looks to be what
index wants.

The array, may be allocated with a set size, and we may use this info
later.

Looks to be unfinished code, that I started but never got to finish.

-- Steve



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 05/11] parse-events: Use proper function parameter type
  2012-04-23  4:58 ` [PATCH 05/11] parse-events: Use proper function parameter type Namhyung Kim
@ 2012-04-23 18:38   ` Steven Rostedt
  0 siblings, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:38 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The param needs to be updated when setting args up so that
> the loop in process_defined_func() can see the correct
> param->type for the farg.

Ouch!

Applied, thanks!

-- Steve

> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-events.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/parse-events.c b/parse-events.c
> index 3e5ac44..b7c81d8 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -3396,6 +3396,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
>  			break;
>  		}
>  		farg = farg->next;
> +		param = param->next;
>  	}
>  
>  	ret = (*func_handle->func)(s, args);



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 06/11] parse-events: Pass string type argument to args
  2012-04-23  4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
@ 2012-04-23 18:41   ` Steven Rostedt
  2012-07-06 11:16   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:41 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> It seems PEVENT_FUNC_ARG_STRING missed passing the allocated
> string to the args array. Fix it.

Another Ouch!

Applied, thanks!

-- Steve

> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-events.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/parse-events.c b/parse-events.c
> index b7c81d8..3b39923 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -3384,6 +3384,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
>  			if (!string->str)
>  				die("malloc str");
>  
> +			args[i] = (unsigned long long)string->str;
>  			strings = string;
>  			trace_seq_destroy(&str);
>  			break;



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed
  2012-04-23  4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
@ 2012-04-23 18:43   ` Steven Rostedt
  2012-07-06 11:17   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:43 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> When memory allocation for the field name is failed, do not
> goto event_failed since we added the event already.
> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>

Applied, Thanks!

-- Steve



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 08/11] parse-events: Fix some comments
  2012-04-23  4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
@ 2012-04-23 18:47   ` Steven Rostedt
  2012-07-06 11:18   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:47 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> Update and add missing argument descriptions and fix some typo
> on function comments.
> 

Applied, thanks!

> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---

>   *
> - * Returns: 0 on success, -1 field not fould, or 1 if buffer is full.
> + * Returns: 0 on success, -1 field not found, or 1 if buffer is full.

Must have been some dvorak/qwerty brain fart (I use dvorak). As, the
qwerty 'l' is the dvorak 'n'.

-- Steve

>   */
>  int pevent_print_num_field(struct trace_seq *s, const char *fmt,
>  			   struct event_format *event, const char *name,



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 09/11] parse-filter: Check result of malloc() during reading token
  2012-04-23  4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
@ 2012-04-23 18:48   ` Steven Rostedt
  2012-04-24  0:15     ` Namhyung Kim
  2012-07-06 11:19   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 1 reply; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:48 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The malloc can fail so the return value should be checked.
> For now, just use malloc_or_die().

Applied, thanks!

Although we will be getting rid of the 'die' feature. But at least this
marks a location that we need to track.

-- Steve

> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-filter.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/parse-filter.c b/parse-filter.c
> index bc62f1f..0e6c0b1 100644
> --- a/parse-filter.c
> +++ b/parse-filter.c
> @@ -96,7 +96,7 @@ static enum event_type read_token(char **tok)
>  	    (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) &&
>  	    pevent_peek_char() == '~') {
>  		/* append it */
> -		*tok = malloc(3);
> +		*tok = malloc_or_die(3);
>  		sprintf(*tok, "%c%c", *token, '~');
>  		free_token(token);
>  		/* Now remove the '~' from the buffer */



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 10/11] parse-filter: Fix signature of create_arg_item()
  2012-04-23  4:58 ` [PATCH 10/11] parse-filter: Fix signature of create_arg_item() Namhyung Kim
@ 2012-04-23 18:57   ` Steven Rostedt
  0 siblings, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:57 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The @type should be a type of enum event_type not enum
> filter_arg_type. This fixes following warning:
> 
>  $ make
>   COMPILE FPIC           parse-events.o
>   COMPILE FPIC           parse-filter.o
> /home/namhyung/project/trace-cmd/parse-filter.c: In function ‘create_arg_item’:
> /home/namhyung/project/trace-cmd/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare]
> /home/namhyung/project/trace-cmd/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]
>   BUILD STATIC LIB       libparsevent.a
>   BUILD STATIC LIB       libtracecmd.a
>   BUILD                  trace-cmd
> /usr/bin/make -C /home/namhyung/project/trace-cmd/Documentation all
> make[1]: Nothing to be done for `all'.
> Note: to build the gui, type "make gui"

Applied thanks!

-- Steve

> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-filter.c |    5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/parse-filter.c b/parse-filter.c
> index 0e6c0b1..fa6e6a2 100644
> --- a/parse-filter.c
> +++ b/parse-filter.c
> @@ -325,9 +325,8 @@ static void free_events(struct event_list *events)
>  }
>  
>  static struct filter_arg *
> -create_arg_item(struct event_format *event,
> -		const char *token, enum filter_arg_type type,
> -		char **error_str)
> +create_arg_item(struct event_format *event, const char *token,
> +		enum event_type type, char **error_str)
>  {
>  	struct format_field *field;
>  	struct filter_arg *arg;



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 11/11] parse-filter: Check return value of arg_to_str()
  2012-04-23  4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
@ 2012-04-23 18:59   ` Steven Rostedt
  2012-07-06 11:20   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-23 18:59 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Namhyung Kim, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> The arg_to_str() can fail so we should handle that case properly.

Applied thanks!

I also applied your first series. I'll be pushing this to kernel.org
shortly.

-- Steve

> 
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-filter.c |   15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 01/11] parse-events: Free flag/sym field on failure path
  2012-04-23 16:21   ` Steven Rostedt
@ 2012-04-24  0:05     ` Namhyung Kim
  2012-04-24  1:07       ` [PATCH v2] " Namhyung Kim
  0 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-24  0:05 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

Hi,

On Mon, 23 Apr 2012 12:21:06 -0400, Steven Rostedt wrote:
> On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
>> If parsing flag/sym field failed after allocating it, it
>> should be freed.
>> 
>> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
>> ---
>>  parse-events.c |   14 +++++++++-----
>>  1 file changed, 9 insertions(+), 5 deletions(-)
>> 
>> diff --git a/parse-events.c b/parse-events.c
>> index bd078ba..81e6581 100644
>> --- a/parse-events.c
>> +++ b/parse-events.c
>> @@ -2166,10 +2166,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
>>  
>>  		value = arg_eval(arg);
>>  		if (value == NULL)
>> -			goto out_free;
>> +			goto out_free_field;
>
> Instead of adding more goto's what, before the first goto "out_free"
> add:
>
> 	field = NULL;
>
> and since the field is allocated and also memset to zero, we could do in
> the out_free:
>
> 	if (field) {
> 		free(field->value);
> 		free(field);
> 	}
>
> I think that would be cleaner.
>
> -- Steve
>

OK, will resend v2.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print
  2012-04-23 16:33   ` Steven Rostedt
@ 2012-04-24  0:09     ` Namhyung Kim
  2012-04-24  0:26       ` Steven Rostedt
  0 siblings, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-04-24  0:09 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

Hi,

On Mon, 23 Apr 2012 12:33:42 -0400, Steven Rostedt wrote:
> On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
>> The concatenation of subsequent DQUOTE'd strings is handled
>> by __read_token() already.
>> 
>
> You missed the point of this concat. It's not connecting "xxx" it is
> connecting "xxx" "yyy" into "xxxyyy", as some events do this.
>

I think I don't :). Please see commit 0f15820 ("parse-events:
Concatinate two strings that are adjacent").

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 09/11] parse-filter: Check result of malloc() during reading token
  2012-04-23 18:48   ` Steven Rostedt
@ 2012-04-24  0:15     ` Namhyung Kim
  0 siblings, 0 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-24  0:15 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

Hi,

On Mon, 23 Apr 2012 14:48:37 -0400, Steven Rostedt wrote:
> On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
>> The malloc can fail so the return value should be checked.
>> For now, just use malloc_or_die().
>
> Applied, thanks!
>
> Although we will be getting rid of the 'die' feature. But at least this
> marks a location that we need to track.
>

Right. The point of this patch was that too. My next step will be the
removal of 'die' at all.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print
  2012-04-24  0:09     ` Namhyung Kim
@ 2012-04-24  0:26       ` Steven Rostedt
  0 siblings, 0 replies; 38+ messages in thread
From: Steven Rostedt @ 2012-04-24  0:26 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Frederic Weisbecker, Ingo Molnar, Arnaldo Carvalho de Melo,
	Borislav Petkov, David Ahern, LKML

On Tue, 2012-04-24 at 09:09 +0900, Namhyung Kim wrote:
> Hi,
> 
> On Mon, 23 Apr 2012 12:33:42 -0400, Steven Rostedt wrote:
> > On Mon, 2012-04-23 at 13:58 +0900, Namhyung Kim wrote:
> >> The concatenation of subsequent DQUOTE'd strings is handled
> >> by __read_token() already.
> >> 
> >
> > You missed the point of this concat. It's not connecting "xxx" it is
> > connecting "xxx" "yyy" into "xxxyyy", as some events do this.
> >
> 
> I think I don't :). Please see commit 0f15820 ("parse-events:
> Concatinate two strings that are adjacent").

Heh, OK, I remember doing it for the print statement, but I guess I
needed to do it for the token too. As the commits for both are almost
identical. As the print was first, it must not have been enough, and I
moved it to the token, but kept the first concat there.

I still want to hold off on this patch just to make sure there's not
something else that was missed.

Thanks,

-- Steve



^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v2] parse-events: Free flag/sym field on failure path
  2012-04-24  0:05     ` Namhyung Kim
@ 2012-04-24  1:07       ` Namhyung Kim
  0 siblings, 0 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-24  1:07 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Namhyung Kim, Frederic Weisbecker, Ingo Molnar,
	Arnaldo Carvalho de Melo, Borislav Petkov, David Ahern, LKML

If parsing flag/sym field failed after allocating it, it
should be freed. As Steven advises, make the field NULL
and check it at out_free instead of adding more goto labels.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/parse-events.c b/parse-events.c
index bd078ba..3ccedd9 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -2147,6 +2147,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 		if (test_type_token(type, token, EVENT_OP, "{"))
 			break;
 
+		field = NULL;
 		arg = alloc_arg();
 
 		free_token(token);
@@ -2199,6 +2200,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 	return type;
 
 out_free:
+	if (field) {
+		free(field->value);
+		free(field);
+	}
 	free_arg(arg);
 	free_token(token);
 	*tok = NULL;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 12/11] parse-events: Cleanup realloc use
  2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
                   ` (10 preceding siblings ...)
  2012-04-23  4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
@ 2012-04-24  1:29 ` Namhyung Kim
  2012-05-15  8:39   ` Namhyung Kim
  2012-07-06 11:21   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  11 siblings, 2 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-04-24  1:29 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Namhyung Kim, Frederic Weisbecker, LKML, Ulrich Drepper

The if branch is completely unnecessary since 'realloc' can
handle NULL pointers for the first parameter.

This patch is just an adoption of Ulrich Drepper's recent
patch on perf tools.

Cc: Ulrich Drepper <drepper@gmail.com>
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 parse-events.c |    8 ++------
 parse-filter.c |   24 ++++++++----------------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index 3ccedd9..9779298 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -627,12 +627,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
 {
 	int i;
 
-	if (!pevent->events)
-		pevent->events = malloc_or_die(sizeof(event));
-	else
-		pevent->events =
-			realloc(pevent->events, sizeof(event) *
-				(pevent->nr_events + 1));
+	pevent->events = realloc(pevent->events, sizeof(event) *
+				 (pevent->nr_events + 1));
 	if (!pevent->events)
 		die("Can not allocate events");
 
diff --git a/parse-filter.c b/parse-filter.c
index bc62f1f..79be550 100644
--- a/parse-filter.c
+++ b/parse-filter.c
@@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id)
 	if (filter_type)
 		return filter_type;
 
-	if (!filter->filters)
-		filter->event_filters =
-			malloc_or_die(sizeof(*filter->event_filters));
-	else {
-		filter->event_filters =
-			realloc(filter->event_filters,
-				sizeof(*filter->event_filters) *
-				(filter->filters + 1));
-		if (!filter->event_filters)
-			die("Could not allocate filter");
-	}
+	filter->event_filters =	realloc(filter->event_filters,
+					sizeof(*filter->event_filters) *
+					(filter->filters + 1));
+	if (!filter->event_filters)
+		die("Could not allocate filter");
 
 	for (i = 0; i < filter->filters; i++) {
 		if (filter->event_filters[i].event_id > id)
@@ -1481,7 +1475,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
 {
 	struct filter_type *filter_type;
 	int count = 0;
-	int *ids;
+	int *ids = NULL;
 	int i;
 
 	if (!filter->filters)
@@ -1505,10 +1499,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
 		default:
 			break;
 		}
-		if (count)
-			ids = realloc(ids, sizeof(*ids) * (count + 1));
-		else
-			ids = malloc(sizeof(*ids));
+
+		ids = realloc(ids, sizeof(*ids) * (count + 1));
 		if (!ids)
 			die("Can't allocate ids");
 		ids[count++] = filter_type->event_id;
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH 12/11] parse-events: Cleanup realloc use
  2012-04-24  1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
@ 2012-05-15  8:39   ` Namhyung Kim
  2012-05-15  8:48     ` Steven Rostedt
  2012-07-06 11:21   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
  1 sibling, 1 reply; 38+ messages in thread
From: Namhyung Kim @ 2012-05-15  8:39 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Frederic Weisbecker, LKML, Ulrich Drepper

Ping?

On Tue, 24 Apr 2012 10:29:44 +0900, Namhyung Kim wrote:
> The if branch is completely unnecessary since 'realloc' can
> handle NULL pointers for the first parameter.
>
> This patch is just an adoption of Ulrich Drepper's recent
> patch on perf tools.
>
> Cc: Ulrich Drepper <drepper@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
>  parse-events.c |    8 ++------
>  parse-filter.c |   24 ++++++++----------------
>  2 files changed, 10 insertions(+), 22 deletions(-)
>
> diff --git a/parse-events.c b/parse-events.c
> index 3ccedd9..9779298 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -627,12 +627,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
>  {
>  	int i;
>  
> -	if (!pevent->events)
> -		pevent->events = malloc_or_die(sizeof(event));
> -	else
> -		pevent->events =
> -			realloc(pevent->events, sizeof(event) *
> -				(pevent->nr_events + 1));
> +	pevent->events = realloc(pevent->events, sizeof(event) *
> +				 (pevent->nr_events + 1));
>  	if (!pevent->events)
>  		die("Can not allocate events");
>  
> diff --git a/parse-filter.c b/parse-filter.c
> index bc62f1f..79be550 100644
> --- a/parse-filter.c
> +++ b/parse-filter.c
> @@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id)
>  	if (filter_type)
>  		return filter_type;
>  
> -	if (!filter->filters)
> -		filter->event_filters =
> -			malloc_or_die(sizeof(*filter->event_filters));
> -	else {
> -		filter->event_filters =
> -			realloc(filter->event_filters,
> -				sizeof(*filter->event_filters) *
> -				(filter->filters + 1));
> -		if (!filter->event_filters)
> -			die("Could not allocate filter");
> -	}
> +	filter->event_filters =	realloc(filter->event_filters,
> +					sizeof(*filter->event_filters) *
> +					(filter->filters + 1));
> +	if (!filter->event_filters)
> +		die("Could not allocate filter");
>  
>  	for (i = 0; i < filter->filters; i++) {
>  		if (filter->event_filters[i].event_id > id)
> @@ -1481,7 +1475,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
>  {
>  	struct filter_type *filter_type;
>  	int count = 0;
> -	int *ids;
> +	int *ids = NULL;
>  	int i;
>  
>  	if (!filter->filters)
> @@ -1505,10 +1499,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
>  		default:
>  			break;
>  		}
> -		if (count)
> -			ids = realloc(ids, sizeof(*ids) * (count + 1));
> -		else
> -			ids = malloc(sizeof(*ids));
> +
> +		ids = realloc(ids, sizeof(*ids) * (count + 1));
>  		if (!ids)
>  			die("Can't allocate ids");
>  		ids[count++] = filter_type->event_id;

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 12/11] parse-events: Cleanup realloc use
  2012-05-15  8:39   ` Namhyung Kim
@ 2012-05-15  8:48     ` Steven Rostedt
  2012-05-15  9:32       ` Namhyung Kim
  0 siblings, 1 reply; 38+ messages in thread
From: Steven Rostedt @ 2012-05-15  8:48 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Frederic Weisbecker, LKML, Ulrich Drepper

On Tue, 2012-05-15 at 17:39 +0900, Namhyung Kim wrote:
> Ping?

The 12/11 fooled me ;-)  I added 1-11 but as my email is not sorted
well, I stopped at 11/11 (thinking that was the last patch).

I'll take a look at this one.

Thanks,

-- Steve



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 12/11] parse-events: Cleanup realloc use
  2012-05-15  8:48     ` Steven Rostedt
@ 2012-05-15  9:32       ` Namhyung Kim
  0 siblings, 0 replies; 38+ messages in thread
From: Namhyung Kim @ 2012-05-15  9:32 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Frederic Weisbecker, LKML, Ulrich Drepper

Hi,

On Tue, 15 May 2012 04:48:45 -0400, Steven Rostedt wrote:
> On Tue, 2012-05-15 at 17:39 +0900, Namhyung Kim wrote:
>> Ping?
>
> The 12/11 fooled me ;-)  I added 1-11 but as my email is not sorted
> well, I stopped at 11/11 (thinking that was the last patch).
>

Sorry, it should be sent separately. I'll not do it again.


> I'll take a look at this one.
>

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Pass string type argument to args
  2012-04-23  4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
  2012-04-23 18:41   ` Steven Rostedt
@ 2012-07-06 11:16   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, namhyung.kim, namhyung, bp, namhyung,
	fweisbec, rostedt, acme, dsahern, tglx

Commit-ID:  3831a42deba59bf26618b0dd6fa1320a0a94ebd9
Gitweb:     http://git.kernel.org/tip/3831a42deba59bf26618b0dd6fa1320a0a94ebd9
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Mon, 23 Apr 2012 13:58:33 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Pass string type argument to args

It seems PEVENT_FUNC_ARG_STRING missed passing the allocated string to
the args array.  Fix it.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-7-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-parse.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 05eb6b4..337ca02 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3489,6 +3489,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
 			if (!string->str)
 				die("malloc str");
 
+			args[i] = (unsigned long long)string->str;
 			strings = string;
 			trace_seq_destroy(&str);
 			break;

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Do not call add_event() again if allocation failed
  2012-04-23  4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
  2012-04-23 18:43   ` Steven Rostedt
@ 2012-07-06 11:17   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, namhyung.kim, namhyung, bp, namhyung,
	fweisbec, rostedt, acme, dsahern, tglx

Commit-ID:  4b5632bc3122ec9b7e875294c8abe92f1573196a
Gitweb:     http://git.kernel.org/tip/4b5632bc3122ec9b7e875294c8abe92f1573196a
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Mon, 23 Apr 2012 13:58:34 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Do not call add_event() again if allocation failed

When memory allocation for the field name is failed, do not goto
event_failed since we added the event already.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-8-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-parse.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 337ca02..99b0cd4 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4770,7 +4770,8 @@ int pevent_parse_event(struct pevent *pevent,
 			arg->field.name = strdup(field->name);
 			if (!arg->field.name) {
 				do_warning("failed to allocate field name");
-				goto event_failed;
+				event->flags |= EVENT_FL_FAILED;
+				return -1;
 			}
 			arg->field.field = field;
 		}

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Fix some comments
  2012-04-23  4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
  2012-04-23 18:47   ` Steven Rostedt
@ 2012-07-06 11:18   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:18 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, namhyung.kim, namhyung, bp, namhyung,
	fweisbec, rostedt, acme, dsahern, tglx

Commit-ID:  16e6b8fdfd181ac79f04ff826c42c7d8a2806a17
Gitweb:     http://git.kernel.org/tip/16e6b8fdfd181ac79f04ff826c42c7d8a2806a17
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Mon, 23 Apr 2012 13:58:35 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Fix some comments

Update and add missing argument descriptions and fix some typo on
function comments.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-9-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-parse.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 99b0cd4..8630160 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4037,8 +4037,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
  * pevent_data_lat_fmt - parse the data for the latency format
  * @pevent: a handle to the pevent
  * @s: the trace_seq to write to
- * @data: the raw data to read from
- * @size: currently unused.
+ * @record: the record to read from
  *
  * This parses out the Latency format (interrupts disabled,
  * need rescheduling, in hard/soft interrupt, preempt count
@@ -4173,10 +4172,7 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid)
  * pevent_data_comm_from_pid - parse the data into the print format
  * @s: the trace_seq to write to
  * @event: the handle to the event
- * @cpu: the cpu the event was recorded on
- * @data: the raw data
- * @size: the size of the raw data
- * @nsecs: the timestamp of the event
+ * @record: the record to read from
  *
  * This parses the raw @data using the given @event information and
  * writes the print format into the trace_seq.
@@ -4944,7 +4940,7 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
  * @record: The record with the field name.
  * @err: print default error if failed.
  *
- * Returns: 0 on success, -1 field not fould, or 1 if buffer is full.
+ * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
  */
 int pevent_print_num_field(struct trace_seq *s, const char *fmt,
 			   struct event_format *event, const char *name,
@@ -4986,11 +4982,12 @@ static void free_func_handle(struct pevent_function_handler *func)
  * pevent_register_print_function - register a helper function
  * @pevent: the handle to the pevent
  * @func: the function to process the helper function
+ * @ret_type: the return type of the helper function
  * @name: the name of the helper function
  * @parameters: A list of enum pevent_func_arg_type
  *
  * Some events may have helper functions in the print format arguments.
- * This allows a plugin to dynmically create a way to process one
+ * This allows a plugin to dynamically create a way to process one
  * of these functions.
  *
  * The @parameters is a variable list of pevent_func_arg_type enums that
@@ -5061,12 +5058,13 @@ int pevent_register_print_function(struct pevent *pevent,
 }
 
 /**
- * pevent_register_event_handle - register a way to parse an event
+ * pevent_register_event_handler - register a way to parse an event
  * @pevent: the handle to the pevent
  * @id: the id of the event to register
  * @sys_name: the system name the event belongs to
  * @event_name: the name of the event
  * @func: the function to call to parse the event information
+ * @context: the data to be passed to @func
  *
  * This function allows a developer to override the parsing of
  * a given event. If for some reason the default print format

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Check result of malloc() during reading token
  2012-04-23  4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
  2012-04-23 18:48   ` Steven Rostedt
@ 2012-07-06 11:19   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, namhyung.kim, namhyung, bp, namhyung,
	fweisbec, rostedt, acme, dsahern, tglx

Commit-ID:  e54b34aed1c4082ed03f4d1f7a19276059b1e30a
Gitweb:     http://git.kernel.org/tip/e54b34aed1c4082ed03f4d1f7a19276059b1e30a
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Mon, 23 Apr 2012 13:58:36 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Check result of malloc() during reading token

The malloc can fail so the return value should be checked.  For now,
just use malloc_or_die().

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-10-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/parse-filter.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 80d872a..d54c2b4 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -96,7 +96,7 @@ static enum event_type read_token(char **tok)
 	    (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) &&
 	    pevent_peek_char() == '~') {
 		/* append it */
-		*tok = malloc(3);
+		*tok = malloc_or_die(3);
 		sprintf(*tok, "%c%c", *token, '~');
 		free_token(token);
 		/* Now remove the '~' from the buffer */

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Check return value of arg_to_str()
  2012-04-23  4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
  2012-04-23 18:59   ` Steven Rostedt
@ 2012-07-06 11:20   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, namhyung.kim, namhyung, bp, namhyung,
	fweisbec, rostedt, acme, dsahern, tglx

Commit-ID:  0fed48341529716c38493be66591bda458921b75
Gitweb:     http://git.kernel.org/tip/0fed48341529716c38493be66591bda458921b75
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Mon, 23 Apr 2012 13:58:38 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Check return value of arg_to_str()

The arg_to_str() can fail so we should handle that case properly.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-12-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/parse-filter.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index d54c2b4..f020ac6 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -2026,11 +2026,13 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
 	char *lstr;
 	char *rstr;
 	char *op;
-	char *str;
+	char *str = NULL;
 	int len;
 
 	lstr = arg_to_str(filter, arg->exp.left);
 	rstr = arg_to_str(filter, arg->exp.right);
+	if (!lstr || !rstr)
+		goto out;
 
 	switch (arg->exp.type) {
 	case FILTER_EXP_ADD:
@@ -2070,6 +2072,7 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
 	len = strlen(op) + strlen(lstr) + strlen(rstr) + 4;
 	str = malloc_or_die(len);
 	snprintf(str, len, "%s %s %s", lstr, op, rstr);
+out:
 	free(lstr);
 	free(rstr);
 
@@ -2086,6 +2089,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
 
 	lstr = arg_to_str(filter, arg->num.left);
 	rstr = arg_to_str(filter, arg->num.right);
+	if (!lstr || !rstr)
+		goto out;
 
 	switch (arg->num.type) {
 	case FILTER_CMP_EQ:
@@ -2122,6 +2127,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
 		break;
 	}
 
+out:
 	free(lstr);
 	free(rstr);
 	return str;
@@ -2272,7 +2278,12 @@ int pevent_filter_compare(struct event_filter *filter1, struct event_filter *fil
 		/* The best way to compare complex filters is with strings */
 		str1 = arg_to_str(filter1, filter_type1->filter);
 		str2 = arg_to_str(filter2, filter_type2->filter);
-		result = strcmp(str1, str2) != 0;
+		if (str1 && str2)
+			result = strcmp(str1, str2) != 0;
+		else
+			/* bail out if allocation fails */
+			result = 1;
+
 		free(str1);
 		free(str2);
 		if (result)

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [tip:perf/core] tools lib traceevent: Cleanup realloc use
  2012-04-24  1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
  2012-05-15  8:39   ` Namhyung Kim
@ 2012-07-06 11:21   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 38+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-07-06 11:21 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, drepper, fweisbec, rostedt,
	namhyung.kim, tglx, namhyung

Commit-ID:  f6ced60fb6c0ee115982157457c47e48802d6e1d
Gitweb:     http://git.kernel.org/tip/f6ced60fb6c0ee115982157457c47e48802d6e1d
Author:     Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Tue, 24 Apr 2012 10:29:44 +0900
Committer:  Namhyung Kim <namhyung@kernel.org>
CommitDate: Wed, 4 Jul 2012 13:40:31 +0900

tools lib traceevent: Cleanup realloc use

The if branch is completely unnecessary since 'realloc' can handle
NULL pointers for the first parameter.

This patch is just an adoption of Ulrich Drepper's recent patch on
perf tools.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/r/1335230984-7613-1-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-parse.c  |    8 ++------
 tools/lib/traceevent/parse-filter.c |   24 ++++++++----------------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index f880db4..5f34aa3 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -633,12 +633,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
 {
 	int i;
 
-	if (!pevent->events)
-		pevent->events = malloc_or_die(sizeof(event));
-	else
-		pevent->events =
-			realloc(pevent->events, sizeof(event) *
-				(pevent->nr_events + 1));
+	pevent->events = realloc(pevent->events, sizeof(event) *
+				 (pevent->nr_events + 1));
 	if (!pevent->events)
 		die("Can not allocate events");
 
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index f020ac6..ad17855 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id)
 	if (filter_type)
 		return filter_type;
 
-	if (!filter->filters)
-		filter->event_filters =
-			malloc_or_die(sizeof(*filter->event_filters));
-	else {
-		filter->event_filters =
-			realloc(filter->event_filters,
-				sizeof(*filter->event_filters) *
-				(filter->filters + 1));
-		if (!filter->event_filters)
-			die("Could not allocate filter");
-	}
+	filter->event_filters =	realloc(filter->event_filters,
+					sizeof(*filter->event_filters) *
+					(filter->filters + 1));
+	if (!filter->event_filters)
+		die("Could not allocate filter");
 
 	for (i = 0; i < filter->filters; i++) {
 		if (filter->event_filters[i].event_id > id)
@@ -1480,7 +1474,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
 {
 	struct filter_type *filter_type;
 	int count = 0;
-	int *ids;
+	int *ids = NULL;
 	int i;
 
 	if (!filter->filters)
@@ -1504,10 +1498,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
 		default:
 			break;
 		}
-		if (count)
-			ids = realloc(ids, sizeof(*ids) * (count + 1));
-		else
-			ids = malloc(sizeof(*ids));
+
+		ids = realloc(ids, sizeof(*ids) * (count + 1));
 		if (!ids)
 			die("Can't allocate ids");
 		ids[count++] = filter_type->event_id;

^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2012-07-06 11:22 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-23  4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
2012-04-23  4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
2012-04-23 16:21   ` Steven Rostedt
2012-04-24  0:05     ` Namhyung Kim
2012-04-24  1:07       ` [PATCH v2] " Namhyung Kim
2012-04-23  4:58 ` [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array() Namhyung Kim
2012-04-23 16:34   ` Steven Rostedt
2012-04-23  4:58 ` [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print Namhyung Kim
2012-04-23 16:33   ` Steven Rostedt
2012-04-24  0:09     ` Namhyung Kim
2012-04-24  0:26       ` Steven Rostedt
2012-04-23  4:58 ` [PATCH 04/11] parse-events: Remove unused arg->dynarray.index Namhyung Kim
2012-04-23 18:35   ` Steven Rostedt
2012-04-23  4:58 ` [PATCH 05/11] parse-events: Use proper function parameter type Namhyung Kim
2012-04-23 18:38   ` Steven Rostedt
2012-04-23  4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
2012-04-23 18:41   ` Steven Rostedt
2012-07-06 11:16   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23  4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
2012-04-23 18:43   ` Steven Rostedt
2012-07-06 11:17   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23  4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
2012-04-23 18:47   ` Steven Rostedt
2012-07-06 11:18   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23  4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
2012-04-23 18:48   ` Steven Rostedt
2012-04-24  0:15     ` Namhyung Kim
2012-07-06 11:19   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23  4:58 ` [PATCH 10/11] parse-filter: Fix signature of create_arg_item() Namhyung Kim
2012-04-23 18:57   ` Steven Rostedt
2012-04-23  4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
2012-04-23 18:59   ` Steven Rostedt
2012-07-06 11:20   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-24  1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
2012-05-15  8:39   ` Namhyung Kim
2012-05-15  8:48     ` Steven Rostedt
2012-05-15  9:32       ` Namhyung Kim
2012-07-06 11:21   ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim

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).