diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/bench/mem-memcpy.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-help.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-probe.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 14 | ||||
-rw-r--r-- | tools/perf/builtin-top.c | 2 | ||||
-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 |
10 files changed, 25 insertions, 25 deletions
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 5165fd1d8d2c..89773178e894 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
@@ -127,11 +127,11 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
127 | return 1; | 127 | return 1; |
128 | } | 128 | } |
129 | 129 | ||
130 | dst = calloc(length, sizeof(char)); | 130 | dst = zalloc(length); |
131 | if (!dst) | 131 | if (!dst) |
132 | die("memory allocation failed - maybe length is too large?\n"); | 132 | die("memory allocation failed - maybe length is too large?\n"); |
133 | 133 | ||
134 | src = calloc(length, sizeof(char)); | 134 | src = zalloc(length); |
135 | if (!src) | 135 | if (!src) |
136 | die("memory allocation failed - maybe length is too large?\n"); | 136 | die("memory allocation failed - maybe length is too large?\n"); |
137 | 137 | ||
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 768f9c826312..9f810b17c25c 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c | |||
@@ -179,7 +179,7 @@ static void add_man_viewer(const char *name) | |||
179 | 179 | ||
180 | while (*p) | 180 | while (*p) |
181 | p = &((*p)->next); | 181 | p = &((*p)->next); |
182 | *p = calloc(1, (sizeof(**p) + len + 1)); | 182 | *p = zalloc(sizeof(**p) + len + 1); |
183 | strncpy((*p)->name, name, len); | 183 | strncpy((*p)->name, name, len); |
184 | } | 184 | } |
185 | 185 | ||
@@ -194,7 +194,7 @@ static void do_add_man_viewer_info(const char *name, | |||
194 | size_t len, | 194 | size_t len, |
195 | const char *value) | 195 | const char *value) |
196 | { | 196 | { |
197 | struct man_viewer_info_list *new = calloc(1, sizeof(*new) + len + 1); | 197 | struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1); |
198 | 198 | ||
199 | strncpy(new->name, name, len); | 199 | strncpy(new->name, name, len); |
200 | new->info = strdup(value); | 200 | new->info = strdup(value); |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index d78a3d945492..a2f6daf01ecb 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -309,9 +309,9 @@ static int synthesize_probe_event(struct probe_point *pp) | |||
309 | { | 309 | { |
310 | char *buf; | 310 | char *buf; |
311 | int i, len, ret; | 311 | int i, len, ret; |
312 | pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char)); | 312 | pp->probes[0] = buf = zalloc(MAX_CMDLEN); |
313 | if (!buf) | 313 | if (!buf) |
314 | die("Failed to allocate memory by calloc."); | 314 | die("Failed to allocate memory by zalloc."); |
315 | ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); | 315 | ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); |
316 | if (ret <= 0 || ret >= MAX_CMDLEN) | 316 | if (ret <= 0 || ret >= MAX_CMDLEN) |
317 | goto error; | 317 | goto error; |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index dbf089b12def..19eb708a706b 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -225,7 +225,7 @@ static void calibrate_sleep_measurement_overhead(void) | |||
225 | static struct sched_atom * | 225 | static struct sched_atom * |
226 | get_new_event(struct task_desc *task, u64 timestamp) | 226 | get_new_event(struct task_desc *task, u64 timestamp) |
227 | { | 227 | { |
228 | struct sched_atom *event = calloc(1, sizeof(*event)); | 228 | struct sched_atom *event = zalloc(sizeof(*event)); |
229 | unsigned long idx = task->nr_events; | 229 | unsigned long idx = task->nr_events; |
230 | size_t size; | 230 | size_t size; |
231 | 231 | ||
@@ -293,7 +293,7 @@ add_sched_event_wakeup(struct task_desc *task, u64 timestamp, | |||
293 | return; | 293 | return; |
294 | } | 294 | } |
295 | 295 | ||
296 | wakee_event->wait_sem = calloc(1, sizeof(*wakee_event->wait_sem)); | 296 | wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem)); |
297 | sem_init(wakee_event->wait_sem, 0, 0); | 297 | sem_init(wakee_event->wait_sem, 0, 0); |
298 | wakee_event->specific_wait = 1; | 298 | wakee_event->specific_wait = 1; |
299 | event->wait_sem = wakee_event->wait_sem; | 299 | event->wait_sem = wakee_event->wait_sem; |
@@ -323,7 +323,7 @@ static struct task_desc *register_pid(unsigned long pid, const char *comm) | |||
323 | if (task) | 323 | if (task) |
324 | return task; | 324 | return task; |
325 | 325 | ||
326 | task = calloc(1, sizeof(*task)); | 326 | task = zalloc(sizeof(*task)); |
327 | task->pid = pid; | 327 | task->pid = pid; |
328 | task->nr = nr_tasks; | 328 | task->nr = nr_tasks; |
329 | strcpy(task->comm, comm); | 329 | strcpy(task->comm, comm); |
@@ -962,9 +962,7 @@ __thread_latency_insert(struct rb_root *root, struct work_atoms *data, | |||
962 | 962 | ||
963 | static void thread_atoms_insert(struct thread *thread) | 963 | static void thread_atoms_insert(struct thread *thread) |
964 | { | 964 | { |
965 | struct work_atoms *atoms; | 965 | struct work_atoms *atoms = zalloc(sizeof(*atoms)); |
966 | |||
967 | atoms = calloc(sizeof(*atoms), 1); | ||
968 | if (!atoms) | 966 | if (!atoms) |
969 | die("No memory"); | 967 | die("No memory"); |
970 | 968 | ||
@@ -996,9 +994,7 @@ add_sched_out_event(struct work_atoms *atoms, | |||
996 | char run_state, | 994 | char run_state, |
997 | u64 timestamp) | 995 | u64 timestamp) |
998 | { | 996 | { |
999 | struct work_atom *atom; | 997 | struct work_atom *atom = zalloc(sizeof(*atom)); |
1000 | |||
1001 | atom = calloc(sizeof(*atom), 1); | ||
1002 | if (!atom) | 998 | if (!atom) |
1003 | die("Non memory"); | 999 | die("Non memory"); |
1004 | 1000 | ||
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index a21247543fc1..4c8653a86aaf 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -181,7 +181,7 @@ static void parse_source(struct sym_entry *syme) | |||
181 | return; | 181 | return; |
182 | 182 | ||
183 | if (syme->src == NULL) { | 183 | if (syme->src == NULL) { |
184 | syme->src = calloc(1, sizeof(*source)); | 184 | syme->src = zalloc(sizeof(*source)); |
185 | if (syme->src == NULL) | 185 | if (syme->src == NULL) |
186 | return; | 186 | return; |
187 | pthread_mutex_init(&syme->src->lock, NULL); | 187 | pthread_mutex_init(&syme->src->lock, NULL); |
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; |