From 364794845cbc49e638b83d7ef739524291e1e961 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 24 Nov 2009 12:05:16 -0200 Subject: perf tools: Introduce zalloc() for the common calloc(1, N) case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way we type less characters and it looks more like the kzalloc kernel counterpart. Signed-off-by: Arnaldo Carvalho de Melo Cc: Frédéric Weisbecker Cc: Mike Galbraith Cc: Peter Zijlstra Cc: Paul Mackerras LKML-Reference: <1259071517-3242-3-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar --- tools/perf/util/header.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/symbol.c | 11 +++++------ tools/perf/util/thread.c | 2 +- tools/perf/util/util.h | 5 +++++ 5 files changed, 13 insertions(+), 9 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 271a1600e6f7..4b586569bb02 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -63,7 +63,7 @@ int perf_header_attr__add_id(struct perf_header_attr *self, u64 id) */ struct perf_header *perf_header__new(void) { - struct perf_header *self = calloc(sizeof(*self), 1); + struct perf_header *self = zalloc(sizeof(*self)); if (self != NULL) { self->size = 1; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 070027469270..9e5dbd66d34d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) if (id == config) { closedir(evt_dir); closedir(sys_dir); - path = calloc(1, sizeof(path)); + path = zalloc(sizeof(path)); path->system = malloc(MAX_EVENT_LENGTH); if (!path->system) { free(path); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index c4ca974b36e3..8db85b4f553f 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -94,15 +94,14 @@ static void kernel_maps__fixup_end(void) static struct symbol *symbol__new(u64 start, u64 len, const char *name) { size_t namelen = strlen(name) + 1; - struct symbol *self = calloc(1, (symbol__priv_size + - sizeof(*self) + namelen)); - if (!self) + struct symbol *self = zalloc(symbol__priv_size + + sizeof(*self) + namelen); + if (self == NULL) return NULL; - if (symbol__priv_size) { - memset(self, 0, symbol__priv_size); + if (symbol__priv_size) self = ((void *)self) + symbol__priv_size; - } + self->start = start; self->end = len ? start + len - 1 : start; diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 0f6d78c9863a..1796625f7784 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -11,7 +11,7 @@ static struct thread *last_match; static struct thread *thread__new(pid_t pid) { - struct thread *self = calloc(1, sizeof(*self)); + struct thread *self = zalloc(sizeof(*self)); if (self != NULL) { self->pid = pid; diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index e1c623e0c99e..30c5517f2f91 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -302,6 +302,11 @@ extern int xdup(int fd); extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); +static inline void *zalloc(size_t size) +{ + return calloc(1, size); +} + static inline size_t xsize_t(off_t len) { return (size_t)len; -- cgit v1.2.3