Re: [PATCH 2/4] tools lib traceevent: Use calloc were applicable

Namhyung Kim
2012-09-19T03:02:39Z

On Mon, 17 Sep 2012 17:50:47 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Replacing the equivalent open coded malloc + memset bits.
>
> 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>
> ---
> tools/lib/traceevent/event-parse.c | 44 ++++++++++++------------------------
> 1 file changed, 14 insertions(+), 30 deletions(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 278f989..5e38d2f 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -117,14 +117,7 @@ void breakpoint(void)
>
> struct print_arg *alloc_arg(void)
> {
> - struct print_arg *arg;
> -
> - arg = malloc_or_die(sizeof(*arg));
> - if (!arg)
> - return NULL;
> - memset(arg, 0, sizeof(*arg));
> -
> - return arg;
> + return calloc(1, sizeof(struct print_arg));
> }

This requires every callsite of the function should handle allocation
failure.

Thanks,
Namhyung