Skip to content

Commit 87162d8

Browse files
committed
tools lib traceevent: Use calloc were applicable
Replacing the equivalent open coded malloc + memset bits. Reviewed-by: Namhyung Kim <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Steven Rostedt <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0dbca1e commit 87162d8

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

tools/lib/traceevent/event-parse.c

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,7 @@ void breakpoint(void)
117117

118118
struct print_arg *alloc_arg(void)
119119
{
120-
struct print_arg *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;
120+
return calloc(1, sizeof(struct print_arg));
128121
}
129122

130123
struct cmdline {
@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent)
619612

620613
static struct event_format *alloc_event(void)
621614
{
622-
struct event_format *event;
623-
624-
event = malloc(sizeof(*event));
625-
if (!event)
626-
return NULL;
627-
memset(event, 0, sizeof(*event));
628-
629-
return event;
615+
return calloc(1, sizeof(struct event_format));
630616
}
631617

632618
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
12401226

12411227
last_token = token;
12421228

1243-
field = malloc_or_die(sizeof(*field));
1244-
memset(field, 0, sizeof(*field));
1229+
field = calloc(1, sizeof(*field));
1230+
if (!field)
1231+
goto fail;
1232+
12451233
field->event = event;
12461234

12471235
/* read the rest of the type */
@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
21812169
if (test_type_token(type, token, EVENT_DELIM, ","))
21822170
goto out_free;
21832171

2184-
field = malloc_or_die(sizeof(*field));
2185-
memset(field, 0, sizeof(*field));
2172+
field = calloc(1, sizeof(*field));
2173+
if (!field)
2174+
goto out_free;
21862175

21872176
value = arg_eval(arg);
21882177
if (value == NULL)
@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent,
51065095
remove_func_handler(pevent, name);
51075096
}
51085097

5109-
func_handle = malloc(sizeof(*func_handle));
5098+
func_handle = calloc(1, sizeof(*func_handle));
51105099
if (!func_handle) {
51115100
do_warning("Failed to allocate function handler");
51125101
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
51135102
}
5114-
memset(func_handle, 0, sizeof(*func_handle));
51155103

51165104
func_handle->ret_type = ret_type;
51175105
func_handle->name = strdup(name);
@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent,
52105198

52115199
not_found:
52125200
/* Save for later use. */
5213-
handle = malloc(sizeof(*handle));
5201+
handle = calloc(1, sizeof(*handle));
52145202
if (!handle) {
52155203
do_warning("Failed to allocate event handler");
52165204
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
52175205
}
52185206

5219-
memset(handle, 0, sizeof(*handle));
52205207
handle->id = id;
52215208
if (event_name)
52225209
handle->event_name = strdup(event_name);
@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent,
52455232
*/
52465233
struct pevent *pevent_alloc(void)
52475234
{
5248-
struct pevent *pevent;
5235+
struct pevent *pevent = calloc(1, sizeof(*pevent));
52495236

5250-
pevent = malloc(sizeof(*pevent));
5251-
if (!pevent)
5252-
return NULL;
5253-
memset(pevent, 0, sizeof(*pevent));
5254-
pevent->ref_count = 1;
5237+
if (pevent)
5238+
pevent->ref_count = 1;
52555239

52565240
return pevent;
52575241
}

0 commit comments

Comments
 (0)