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

From: Namhyung Kim
Date: Tue Sep 18 2012 - 23:02:30 EST


On Mon, 17 Sep 2012 17:50:47 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> Replacing the equivalent open coded malloc + memset bits.
>
> Cc: David Ahern <dsahern@xxxxxxxxx>
> Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Mike Galbraith <efault@xxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxx>
> Cc: Paul Mackerras <paulus@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Link: http://lkml.kernel.org/n/tip-598fjtjbzal4wxh7fp0yv0q1@xxxxxxxxxxxxxx
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> ---
> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/