tools lib traceevent: Use calloc were applicable

Replacing the equivalent open coded malloc + memset bits.
Reviewed-by: default avatarNamhyung 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0dbca1e3
...@@ -117,14 +117,7 @@ void breakpoint(void) ...@@ -117,14 +117,7 @@ void breakpoint(void)
struct print_arg *alloc_arg(void) struct print_arg *alloc_arg(void)
{ {
struct print_arg *arg; return calloc(1, sizeof(struct print_arg));
arg = malloc_or_die(sizeof(*arg));
if (!arg)
return NULL;
memset(arg, 0, sizeof(*arg));
return arg;
} }
struct cmdline { struct cmdline {
...@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent) ...@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent)
static struct event_format *alloc_event(void) static struct event_format *alloc_event(void)
{ {
struct event_format *event; return calloc(1, sizeof(struct event_format));
event = malloc(sizeof(*event));
if (!event)
return NULL;
memset(event, 0, sizeof(*event));
return event;
} }
static void add_event(struct pevent *pevent, struct event_format *event) 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,8 +1226,10 @@ static int event_read_fields(struct event_format *event, struct format_field **f
last_token = token; last_token = token;
field = malloc_or_die(sizeof(*field)); field = calloc(1, sizeof(*field));
memset(field, 0, sizeof(*field)); if (!field)
goto fail;
field->event = event; field->event = event;
/* read the rest of the type */ /* read the rest of the type */
...@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** ...@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
if (test_type_token(type, token, EVENT_DELIM, ",")) if (test_type_token(type, token, EVENT_DELIM, ","))
goto out_free; goto out_free;
field = malloc_or_die(sizeof(*field)); field = calloc(1, sizeof(*field));
memset(field, 0, sizeof(*field)); if (!field)
goto out_free;
value = arg_eval(arg); value = arg_eval(arg);
if (value == NULL) if (value == NULL)
...@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent, ...@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent,
remove_func_handler(pevent, name); remove_func_handler(pevent, name);
} }
func_handle = malloc(sizeof(*func_handle)); func_handle = calloc(1, sizeof(*func_handle));
if (!func_handle) { if (!func_handle) {
do_warning("Failed to allocate function handler"); do_warning("Failed to allocate function handler");
return PEVENT_ERRNO__MEM_ALLOC_FAILED; return PEVENT_ERRNO__MEM_ALLOC_FAILED;
} }
memset(func_handle, 0, sizeof(*func_handle));
func_handle->ret_type = ret_type; func_handle->ret_type = ret_type;
func_handle->name = strdup(name); func_handle->name = strdup(name);
...@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent, ...@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent,
not_found: not_found:
/* Save for later use. */ /* Save for later use. */
handle = malloc(sizeof(*handle)); handle = calloc(1, sizeof(*handle));
if (!handle) { if (!handle) {
do_warning("Failed to allocate event handler"); do_warning("Failed to allocate event handler");
return PEVENT_ERRNO__MEM_ALLOC_FAILED; return PEVENT_ERRNO__MEM_ALLOC_FAILED;
} }
memset(handle, 0, sizeof(*handle));
handle->id = id; handle->id = id;
if (event_name) if (event_name)
handle->event_name = strdup(event_name); handle->event_name = strdup(event_name);
...@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent, ...@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent,
*/ */
struct pevent *pevent_alloc(void) struct pevent *pevent_alloc(void)
{ {
struct pevent *pevent; struct pevent *pevent = calloc(1, sizeof(*pevent));
pevent = malloc(sizeof(*pevent)); if (pevent)
if (!pevent) pevent->ref_count = 1;
return NULL;
memset(pevent, 0, sizeof(*pevent));
pevent->ref_count = 1;
return pevent; return pevent;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment