diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-12 14:39:59 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-24 11:12:31 -0400 |
commit | 87162d816f5f344d72e25249acd9b823b646a5c9 (patch) | |
tree | 6169be8e7416137a1ce90b49dc6a668503f0b82d /tools/lib | |
parent | 0dbca1e364aba20dba70d88c083239c5152440ac (diff) |
tools lib traceevent: Use calloc were applicable
Replacing the equivalent open coded malloc + memset bits.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-598fjtjbzal4wxh7fp0yv0q1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/traceevent/event-parse.c | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 2e05d567353e..2aeae5555a63 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
@@ -117,14 +117,7 @@ void breakpoint(void) | |||
117 | 117 | ||
118 | struct print_arg *alloc_arg(void) | 118 | struct print_arg *alloc_arg(void) |
119 | { | 119 | { |
120 | struct print_arg *arg; | 120 | return calloc(1, sizeof(struct print_arg)); |
121 | |||
122 | arg = malloc_or_die(sizeof(*arg)); | ||
123 | if (!arg) | ||
124 | return NULL; | ||
125 | memset(arg, 0, sizeof(*arg)); | ||
126 | |||
127 | return arg; | ||
128 | } | 121 | } |
129 | 122 | ||
130 | struct cmdline { | 123 | struct cmdline { |
@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent) | |||
619 | 612 | ||
620 | static struct event_format *alloc_event(void) | 613 | static struct event_format *alloc_event(void) |
621 | { | 614 | { |
622 | struct event_format *event; | 615 | return calloc(1, sizeof(struct event_format)); |
623 | |||
624 | event = malloc(sizeof(*event)); | ||
625 | if (!event) | ||
626 | return NULL; | ||
627 | memset(event, 0, sizeof(*event)); | ||
628 | |||
629 | return event; | ||
630 | } | 616 | } |
631 | 617 | ||
632 | static void add_event(struct pevent *pevent, struct event_format *event) | 618 | static void add_event(struct pevent *pevent, struct event_format *event) |
@@ -1240,8 +1226,10 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1240 | 1226 | ||
1241 | last_token = token; | 1227 | last_token = token; |
1242 | 1228 | ||
1243 | field = malloc_or_die(sizeof(*field)); | 1229 | field = calloc(1, sizeof(*field)); |
1244 | memset(field, 0, sizeof(*field)); | 1230 | if (!field) |
1231 | goto fail; | ||
1232 | |||
1245 | field->event = event; | 1233 | field->event = event; |
1246 | 1234 | ||
1247 | /* read the rest of the type */ | 1235 | /* read the rest of the type */ |
@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** | |||
2181 | if (test_type_token(type, token, EVENT_DELIM, ",")) | 2169 | if (test_type_token(type, token, EVENT_DELIM, ",")) |
2182 | goto out_free; | 2170 | goto out_free; |
2183 | 2171 | ||
2184 | field = malloc_or_die(sizeof(*field)); | 2172 | field = calloc(1, sizeof(*field)); |
2185 | memset(field, 0, sizeof(*field)); | 2173 | if (!field) |
2174 | goto out_free; | ||
2186 | 2175 | ||
2187 | value = arg_eval(arg); | 2176 | value = arg_eval(arg); |
2188 | if (value == NULL) | 2177 | if (value == NULL) |
@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent, | |||
5106 | remove_func_handler(pevent, name); | 5095 | remove_func_handler(pevent, name); |
5107 | } | 5096 | } |
5108 | 5097 | ||
5109 | func_handle = malloc(sizeof(*func_handle)); | 5098 | func_handle = calloc(1, sizeof(*func_handle)); |
5110 | if (!func_handle) { | 5099 | if (!func_handle) { |
5111 | do_warning("Failed to allocate function handler"); | 5100 | do_warning("Failed to allocate function handler"); |
5112 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; | 5101 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
5113 | } | 5102 | } |
5114 | memset(func_handle, 0, sizeof(*func_handle)); | ||
5115 | 5103 | ||
5116 | func_handle->ret_type = ret_type; | 5104 | func_handle->ret_type = ret_type; |
5117 | func_handle->name = strdup(name); | 5105 | func_handle->name = strdup(name); |
@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent, | |||
5210 | 5198 | ||
5211 | not_found: | 5199 | not_found: |
5212 | /* Save for later use. */ | 5200 | /* Save for later use. */ |
5213 | handle = malloc(sizeof(*handle)); | 5201 | handle = calloc(1, sizeof(*handle)); |
5214 | if (!handle) { | 5202 | if (!handle) { |
5215 | do_warning("Failed to allocate event handler"); | 5203 | do_warning("Failed to allocate event handler"); |
5216 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; | 5204 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
5217 | } | 5205 | } |
5218 | 5206 | ||
5219 | memset(handle, 0, sizeof(*handle)); | ||
5220 | handle->id = id; | 5207 | handle->id = id; |
5221 | if (event_name) | 5208 | if (event_name) |
5222 | handle->event_name = strdup(event_name); | 5209 | handle->event_name = strdup(event_name); |
@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent, | |||
5245 | */ | 5232 | */ |
5246 | struct pevent *pevent_alloc(void) | 5233 | struct pevent *pevent_alloc(void) |
5247 | { | 5234 | { |
5248 | struct pevent *pevent; | 5235 | struct pevent *pevent = calloc(1, sizeof(*pevent)); |
5249 | 5236 | ||
5250 | pevent = malloc(sizeof(*pevent)); | 5237 | if (pevent) |
5251 | if (!pevent) | 5238 | pevent->ref_count = 1; |
5252 | return NULL; | ||
5253 | memset(pevent, 0, sizeof(*pevent)); | ||
5254 | pevent->ref_count = 1; | ||
5255 | 5239 | ||
5256 | return pevent; | 5240 | return pevent; |
5257 | } | 5241 | } |