diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-24 09:05:16 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-24 10:37:02 -0500 |
commit | 364794845cbc49e638b83d7ef739524291e1e961 (patch) | |
tree | e720975b26d307d6566afb9305c9f6e44290a7da /tools/perf/util | |
parent | b32d133aec5dc882cf783a293f393bfb3f4379e1 (diff) |
perf tools: Introduce zalloc() for the common calloc(1, N) case
This way we type less characters and it looks more like the
kzalloc kernel counterpart.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1259071517-3242-3-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/header.c | 2 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 2 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 11 | ||||
-rw-r--r-- | tools/perf/util/thread.c | 2 | ||||
-rw-r--r-- | tools/perf/util/util.h | 5 |
5 files changed, 13 insertions, 9 deletions
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) | |||
63 | */ | 63 | */ |
64 | struct perf_header *perf_header__new(void) | 64 | struct perf_header *perf_header__new(void) |
65 | { | 65 | { |
66 | struct perf_header *self = calloc(sizeof(*self), 1); | 66 | struct perf_header *self = zalloc(sizeof(*self)); |
67 | 67 | ||
68 | if (self != NULL) { | 68 | if (self != NULL) { |
69 | self->size = 1; | 69 | 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) | |||
197 | if (id == config) { | 197 | if (id == config) { |
198 | closedir(evt_dir); | 198 | closedir(evt_dir); |
199 | closedir(sys_dir); | 199 | closedir(sys_dir); |
200 | path = calloc(1, sizeof(path)); | 200 | path = zalloc(sizeof(path)); |
201 | path->system = malloc(MAX_EVENT_LENGTH); | 201 | path->system = malloc(MAX_EVENT_LENGTH); |
202 | if (!path->system) { | 202 | if (!path->system) { |
203 | free(path); | 203 | 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) | |||
94 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) | 94 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) |
95 | { | 95 | { |
96 | size_t namelen = strlen(name) + 1; | 96 | size_t namelen = strlen(name) + 1; |
97 | struct symbol *self = calloc(1, (symbol__priv_size + | 97 | struct symbol *self = zalloc(symbol__priv_size + |
98 | sizeof(*self) + namelen)); | 98 | sizeof(*self) + namelen); |
99 | if (!self) | 99 | if (self == NULL) |
100 | return NULL; | 100 | return NULL; |
101 | 101 | ||
102 | if (symbol__priv_size) { | 102 | if (symbol__priv_size) |
103 | memset(self, 0, symbol__priv_size); | ||
104 | self = ((void *)self) + symbol__priv_size; | 103 | self = ((void *)self) + symbol__priv_size; |
105 | } | 104 | |
106 | self->start = start; | 105 | self->start = start; |
107 | self->end = len ? start + len - 1 : start; | 106 | self->end = len ? start + len - 1 : start; |
108 | 107 | ||
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; | |||
11 | 11 | ||
12 | static struct thread *thread__new(pid_t pid) | 12 | static struct thread *thread__new(pid_t pid) |
13 | { | 13 | { |
14 | struct thread *self = calloc(1, sizeof(*self)); | 14 | struct thread *self = zalloc(sizeof(*self)); |
15 | 15 | ||
16 | if (self != NULL) { | 16 | if (self != NULL) { |
17 | self->pid = pid; | 17 | 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); | |||
302 | extern FILE *xfdopen(int fd, const char *mode); | 302 | extern FILE *xfdopen(int fd, const char *mode); |
303 | extern int xmkstemp(char *template); | 303 | extern int xmkstemp(char *template); |
304 | 304 | ||
305 | static inline void *zalloc(size_t size) | ||
306 | { | ||
307 | return calloc(1, size); | ||
308 | } | ||
309 | |||
305 | static inline size_t xsize_t(off_t len) | 310 | static inline size_t xsize_t(off_t len) |
306 | { | 311 | { |
307 | return (size_t)len; | 312 | return (size_t)len; |