tools lib traceevent: Get rid of die() in pevent_filter_clear_trivial()
authorNamhyung Kim <namhyung@kernel.org>
Mon, 9 Dec 2013 05:34:09 +0000 (14:34 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2013 18:39:57 +0000 (15:39 -0300)
Change the function signature to return error code and not call die()
anymore.

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-13-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/event-parse.h
tools/lib/traceevent/parse-filter.c

index 620c27a72960f0cfe19a6044f21c4565a4e0746b..6e23f197175fced17734dfb8b7ffd6b7f620d82f 100644 (file)
@@ -860,7 +860,7 @@ int pevent_event_filtered(struct event_filter *filter,
 
 void pevent_filter_reset(struct event_filter *filter);
 
-void pevent_filter_clear_trivial(struct event_filter *filter,
+int pevent_filter_clear_trivial(struct event_filter *filter,
                                 enum filter_trivial_type type);
 
 void pevent_filter_free(struct event_filter *filter);
index a4d5bb23a110895770fe9f480eb1d52fd45f0959..ab402fb2dcf743e224831c8d863fe4f01eb45b0f 100644 (file)
@@ -1504,8 +1504,10 @@ int pevent_update_trivial(struct event_filter *dest, struct event_filter *source
  * @type: remove only true, false, or both
  *
  * Removes filters that only contain a TRUE or FALES boolean arg.
+ *
+ * Returns 0 on success and -1 if there was a problem.
  */
-void pevent_filter_clear_trivial(struct event_filter *filter,
+int pevent_filter_clear_trivial(struct event_filter *filter,
                                 enum filter_trivial_type type)
 {
        struct filter_type *filter_type;
@@ -1514,13 +1516,15 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
        int i;
 
        if (!filter->filters)
-               return;
+               return 0;
 
        /*
         * Two steps, first get all ids with trivial filters.
         *  then remove those ids.
         */
        for (i = 0; i < filter->filters; i++) {
+               int *new_ids;
+
                filter_type = &filter->event_filters[i];
                if (filter_type->filter->type != FILTER_ARG_BOOLEAN)
                        continue;
@@ -1535,19 +1539,24 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
                        break;
                }
 
-               ids = realloc(ids, sizeof(*ids) * (count + 1));
-               if (!ids)
-                       die("Can't allocate ids");
+               new_ids = realloc(ids, sizeof(*ids) * (count + 1));
+               if (!new_ids) {
+                       free(ids);
+                       return -1;
+               }
+
+               ids = new_ids;
                ids[count++] = filter_type->event_id;
        }
 
        if (!count)
-               return;
+               return 0;
 
        for (i = 0; i < count; i++)
                pevent_filter_remove_event(filter, ids[i]);
 
        free(ids);
+       return 0;
 }
 
 /**