tools lib traceevent: Get rid of malloc_or_die() in add_event()
authorNamhyung Kim <namhyung@kernel.org>
Mon, 9 Dec 2013 05:34:04 +0000 (14:34 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2013 18:39:40 +0000 (15:39 -0300)
Make it return error value since its only caller find_event() now can
handle allocation error properly.

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: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386567251-22751-8-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/parse-filter.c

index b3a61d4fe38e2ffade7de3a9449c84bd8eda3f23..2b73abfb0c9fd8246db4c7e1c9b766c82ad88054 100644 (file)
@@ -245,15 +245,19 @@ static void free_arg(struct filter_arg *arg)
        free(arg);
 }
 
-static void add_event(struct event_list **events,
+static int add_event(struct event_list **events,
                      struct event_format *event)
 {
        struct event_list *list;
 
-       list = malloc_or_die(sizeof(*list));
+       list = malloc(sizeof(*list));
+       if (list == NULL)
+               return -1;
+
        list->next = *events;
        *events = list;
        list->event = event;
+       return 0;
 }
 
 static int event_match(struct event_format *event,
@@ -276,6 +280,7 @@ find_event(struct pevent *pevent, struct event_list **events,
        regex_t ereg;
        regex_t sreg;
        int match = 0;
+       int fail = 0;
        char *reg;
        int ret;
        int i;
@@ -310,7 +315,10 @@ find_event(struct pevent *pevent, struct event_list **events,
                event = pevent->events[i];
                if (event_match(event, sys_name ? &sreg : NULL, &ereg)) {
                        match = 1;
-                       add_event(events, event);
+                       if (add_event(events, event) < 0) {
+                               fail = 1;
+                               break;
+                       }
                }
        }
 
@@ -320,6 +328,8 @@ find_event(struct pevent *pevent, struct event_list **events,
 
        if (!match)
                return -1;
+       if (fail)
+               return -2;
 
        return 0;
 }