#include <errno.h>
#include <stdbool.h>
#include <linux/coresight-pmu.h>
-#include <linux/zalloc.h>
+#include <stdlib.h>
#include <api/fs/fs.h>
#include "../../../util/auxtrace.h"
/* arm_spe_xxxxxxxxx\0 */
char arm_spe_pmu_name[sizeof(ARM_SPE_PMU_NAME) + 10];
- arm_spe_pmus = zalloc(sizeof(struct perf_pmu *) * nr_cpus);
+ arm_spe_pmus = calloc(nr_cpus, sizeof(struct perf_pmu *));
if (!arm_spe_pmus) {
pr_err("spes alloc failed\n");
*err = -ENOMEM;
if (!(*nr_ptts))
goto out;
- hisi_ptt_pmus = zalloc(sizeof(struct perf_pmu *) * (*nr_ptts));
+ hisi_ptt_pmus = calloc((*nr_ptts), sizeof(struct perf_pmu *));
if (!hisi_ptt_pmus) {
pr_err("hisi_ptt alloc failed\n");
*err = -ENOMEM;
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/string.h>
+#include <linux/zalloc.h>
#include "../../util/evlist.h"
#include "../../util/debug.h"
#include "arch-tests.h"
#include "linux/perf_event.h"
-#include "linux/zalloc.h"
#include "tests/tests.h"
#include "../perf-sys.h"
#include "pmu.h"
0xcc, /* int 3 */
};
- p = zalloc(2 * page_size);
+ p = calloc(2, page_size);
if (!p) {
printf("malloc() failed. %m");
return 1;
struct thread *thread)
{
struct regs_dump *regs = perf_sample__user_regs(sample);
- u64 *buf;
+ u64 *buf = calloc(PERF_REGS_MAX, sizeof(u64));
- buf = malloc(sizeof(u64) * PERF_REGS_MAX);
if (!buf) {
pr_debug("failed to allocate sample uregs data\n");
return -1;
}
-#ifdef MEMORY_SANITIZER
- /*
- * Assignments to buf in the assembly function perf_regs_load aren't
- * seen by memory sanitizer. Zero the memory to convince memory
- * sanitizer the memory is initialized.
- */
- memset(buf, 0, sizeof(u64) * PERF_REGS_MAX);
-#endif
perf_regs_load(buf);
regs->abi = PERF_SAMPLE_REGS_ABI;
regs->regs = buf;
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/perf_event.h>
-#include <linux/zalloc.h>
#include <api/fs/fs.h>
#include <api/io_dir.h>
#include <internal/cpumap.h>
#include <linux/kernel.h>
#include <linux/time64.h>
#include <linux/numa.h>
-#include <linux/zalloc.h>
#include "../util/header.h"
#include "../util/mutex.h"
int nodes;
int n, t;
- node_present = (char *)malloc(g->p.nr_nodes * sizeof(char));
+ node_present = calloc(g->p.nr_nodes, sizeof(char));
BUG_ON(!node_present);
- for (nodes = 0; nodes < g->p.nr_nodes; nodes++)
- node_present[nodes] = 0;
for (t = 0; t < g->p.nr_threads; t++) {
struct thread_data *td;
if (!g->p.show_convergence && !g->p.measure_convergence)
return;
- nodes = (int *)malloc(g->p.nr_nodes * sizeof(int));
+ nodes = calloc(g->p.nr_nodes, sizeof(int));
BUG_ON(!nodes);
- for (node = 0; node < g->p.nr_nodes; node++)
- nodes[node] = 0;
loops_done_min = -1;
loops_done_max = 0;
bind_to_memnode(td->bind_node);
bind_to_cpumask(td->bind_cpumask);
- pthreads = zalloc(g->p.nr_threads * sizeof(pthread_t));
+ pthreads = calloc(g->p.nr_threads, sizeof(pthread_t));
process_data = setup_private_data(g->p.bytes_process);
if (g->p.show_details >= 3) {
if (init())
return -1;
- pids = zalloc(g->p.nr_proc * sizeof(*pids));
+ pids = calloc(g->p.nr_proc, sizeof(*pids));
pid = -1;
if (g->p.serialize_startup) {
argc = parse_options(argc, argv, options,
bench_sched_message_usage, 0);
- worker_tab = malloc(num_fds * 2 * num_groups * sizeof(union messaging_worker));
+ worker_tab = calloc(num_fds * 2 * num_groups, sizeof(union messaging_worker));
if (!worker_tab)
err(EXIT_FAILURE, "main:malloc()");
#include <linux/list.h>
#include "util/cache.h"
#include <linux/rbtree.h>
-#include <linux/zalloc.h>
#include "util/symbol.h"
#include "util/debug.h"
if (!c2c_he->nodeset)
goto out_free;
- c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
+ c2c_he->node_stats = calloc(c2c.nodes_cnt, sizeof(*c2c_he->node_stats));
if (!c2c_he->node_stats)
goto out_free;
if (!n)
return -EINVAL;
- nodes = zalloc(sizeof(unsigned long *) * c2c.nodes_cnt);
+ nodes = calloc(c2c.nodes_cnt, sizeof(unsigned long *));
if (!nodes)
return -ENOMEM;
c2c.nodes = nodes;
- cpu2node = zalloc(sizeof(int) * c2c.cpus_cnt);
+ cpu2node = calloc(c2c.cpus_cnt, sizeof(int));
if (!cpu2node)
return -ENOMEM;
return -EINVAL;
}
- data__files = zalloc(sizeof(*data__files) * data__files_cnt);
+ data__files = calloc(data__files_cnt, sizeof(*data__files));
if (!data__files)
return -ENOMEM;
#include <linux/capability.h>
#include <linux/err.h>
#include <linux/string.h>
+#include <linux/zalloc.h>
#include <sys/stat.h>
#include "debug.h"
struct __top_cpus_runtime *cpus_runtime;
int ret = 0;
- cpus_runtime = zalloc(sizeof(struct __top_cpus_runtime) * (MAX_NR_CPUS + 1));
+ cpus_runtime = calloc(MAX_NR_CPUS + 1, sizeof(struct __top_cpus_runtime));
if (!cpus_runtime)
return -1;
thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits,
thread_data->mask->maps.nbits);
if (mmap) {
- thread_data->maps = zalloc(thread_data->nr_mmaps * sizeof(struct mmap *));
+ thread_data->maps = calloc(thread_data->nr_mmaps, sizeof(struct mmap *));
if (!thread_data->maps)
return -ENOMEM;
}
if (overwrite_mmap) {
- thread_data->overwrite_maps = zalloc(thread_data->nr_mmaps * sizeof(struct mmap *));
+ thread_data->overwrite_maps = calloc(thread_data->nr_mmaps, sizeof(struct mmap *));
if (!thread_data->overwrite_maps) {
zfree(&thread_data->maps);
return -ENOMEM;
int t, ret;
struct record_thread *thread_data;
- rec->thread_data = zalloc(rec->nr_threads * sizeof(*(rec->thread_data)));
+ rec->thread_data = calloc(rec->nr_threads, sizeof(*(rec->thread_data)));
if (!rec->thread_data) {
pr_err("Failed to allocate thread data\n");
return -ENOMEM;
{
int t, ret;
- rec->thread_masks = zalloc(nr_threads * sizeof(*(rec->thread_masks)));
+ rec->thread_masks = calloc(nr_threads, sizeof(*(rec->thread_masks)));
if (!rec->thread_masks) {
pr_err("Failed to allocate thread masks\n");
return -ENOMEM;
return -ENOMEM;
}
- spec = zalloc(topo->nr * sizeof(char *));
+ spec = calloc(topo->nr, sizeof(char *));
if (!spec) {
pr_err("Failed to allocate NUMA spec\n");
ret = -ENOMEM;
{
int i, ret;
- idle_threads = zalloc(ncpu * sizeof(struct thread *));
+ idle_threads = calloc(ncpu, sizeof(struct thread *));
if (!idle_threads)
return -ENOMEM;
if (!sched->cpu_last_switched)
return -1;
- sched->curr_pid = malloc(MAX_CPUS * sizeof(*(sched->curr_pid)));
+ sched->curr_pid = calloc(MAX_CPUS, sizeof(*(sched->curr_pid)));
if (!sched->curr_pid) {
zfree(&sched->cpu_last_switched);
return -1;
sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF);
if (sched->map.comp) {
- sched->map.comp_cpus = zalloc(sched->max_cpu.cpu * sizeof(int));
+ sched->map.comp_cpus = calloc(sched->max_cpu.cpu, sizeof(int));
if (!sched->map.comp_cpus)
return -1;
}
static int have_cmd(int argc, const char **argv)
{
- char **__argv = malloc(sizeof(const char *) * argc);
+ char **__argv = calloc(argc, sizeof(const char *));
if (!__argv) {
pr_err("malloc failed\n");
}
}
- __argv = malloc((argc + 6) * sizeof(const char *));
+ __argv = calloc(argc + 6, sizeof(const char *));
if (!__argv) {
pr_err("malloc failed\n");
err = -ENOMEM;
dup2(live_pipe[0], 0);
close(live_pipe[1]);
- __argv = malloc((argc + 4) * sizeof(const char *));
+ __argv = calloc(argc + 4, sizeof(const char *));
if (!__argv) {
pr_err("malloc failed\n");
err = -ENOMEM;
}
}
- __argv = malloc((argc + 2) * sizeof(const char *));
+ __argv = calloc(argc + 2, sizeof(const char *));
if (!__argv) {
pr_err("malloc failed\n");
err = -ENOMEM;
}
if (stat_config.walltime_run_table) {
- stat_config.walltime_run = zalloc(stat_config.run_count * sizeof(stat_config.walltime_run[0]));
+ stat_config.walltime_run = calloc(stat_config.run_count, sizeof(stat_config.walltime_run[0]));
if (!stat_config.walltime_run) {
pr_err("failed to setup -r option");
goto out;
struct str_node *pos;
size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier);
- trace->ev_qualifier_ids.entries = malloc(nr_allocated *
- sizeof(trace->ev_qualifier_ids.entries[0]));
-
+ trace->ev_qualifier_ids.entries = calloc(nr_allocated, sizeof(trace->ev_qualifier_ids.entries[0]));
if (trace->ev_qualifier_ids.entries == NULL) {
fputs("Error:\tNot enough memory for allocating events qualifier ids\n",
trace->output);
/*
* Phase 2 -- allocate big enough line table
*/
- *tab = malloc(nr_total * sizeof(**tab));
+ *tab = calloc(nr_total, sizeof(**tab));
if (!*tab)
return JVMTI_ERROR_OUT_OF_MEMORY;
}
nr_lines = 0;
} else if (nr_lines > 0) {
- line_file_names = malloc(sizeof(char*) * nr_lines);
+ line_file_names = calloc(nr_lines, sizeof(char *));
if (!line_file_names) {
warnx("jvmti: cannot allocate space for line table method names");
} else {
- memset(line_file_names, 0, sizeof(char*) * nr_lines);
ret = fill_source_filenames(jvmti, nr_lines, line_tab, line_file_names);
if (ret != JVMTI_ERROR_NONE) {
warnx("jvmti: fill_source_filenames failed");
#include <linux/kernel.h>
#include <linux/rbtree.h>
#include <linux/types.h>
+#include <linux/zalloc.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include "debug.h"
#include "event.h"
#include "util/synthetic-events.h"
-#include <linux/zalloc.h>
#include <perf/event.h>
#include <internal/threadmap.h>
// SPDX-License-Identifier: GPL-2.0
#include <string.h>
#include <linux/compiler.h>
+#include <linux/zalloc.h>
#include <assert.h>
#include <inttypes.h>
#include "../annotate-data.h"
if (!metadata)
return NULL;
- metadata->prog_names = zalloc(nr_prog_tags * sizeof(char *));
+ metadata->prog_names = calloc(nr_prog_tags, sizeof(char *));
if (!metadata->prog_names) {
bpf_metadata_free(metadata);
return NULL;
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/err.h>
-#include <linux/zalloc.h>
#include <linux/perf_event.h>
#include <api/fs/fs.h>
#include <bpf/bpf.h>
*/
ncpus = env->nr_cpus_avail ?: MAX_CPUS;
- stream = zalloc(sizeof(*stream) * ncpus);
+ stream = calloc(ncpus, sizeof(*stream));
if (!stream) {
pr_err("Failed to allocate streams.\n");
return -ENOMEM;
if (WARN_ON(!data->is_dir))
return -EINVAL;
- files = zalloc(nr * sizeof(*files));
+ files = calloc(nr, sizeof(*files));
if (!files)
return -ENOMEM;
#include "callchain.h"
#include "call-path.h"
#include "db-export.h"
-#include <linux/zalloc.h>
int db_export__init(struct db_export *dbe)
{
#include <unistd.h>
#include <linux/string.h>
+#include <linux/zalloc.h>
#include <subcmd/run-command.h>
#include "annotate.h"
#include <unistd.h>
#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
#include <linux/perf_event.h>
-#include <linux/zalloc.h>
#include "cpumap.h"
#include "dso.h"
#include "event.h"
bool overwrite)
{
int i;
- struct mmap *map;
+ struct mmap *map = calloc(evlist->core.nr_mmaps, sizeof(struct mmap));
- map = zalloc(evlist->core.nr_mmaps * sizeof(struct mmap));
if (!map)
return NULL;
if (!cmdline)
return -1;
- argv = zalloc(sizeof(char *) * (nr + 1));
+ argv = calloc(nr + 1, sizeof(char *));
if (!argv)
goto error;
if (do_read_u32(ff, &nr))
return -1;
- nodes = zalloc(sizeof(*nodes) * nr);
+ nodes = calloc(nr, sizeof(*nodes));
if (!nodes)
return -ENOMEM;
if (do_read_u32(ff, &cnt))
return -1;
- caches = zalloc(sizeof(*caches) * cnt);
+ caches = calloc(cnt, sizeof(*caches));
if (!caches)
return -1;
if (do_read_u64(ff, &nr))
return -1;
- nodes = zalloc(sizeof(*nodes) * nr);
+ nodes = calloc(nr, sizeof(*nodes));
if (!nodes)
return -1;
if (do_read_u32(ff, &nr))
return -1;
- nodes = zalloc(sizeof(*nodes) * nr);
+ nodes = calloc(nr, sizeof(*nodes));
if (!nodes)
return -ENOMEM;
if (!nr_pmu_caps)
return 0;
- *caps = zalloc(sizeof(char *) * nr_pmu_caps);
+ *caps = calloc(nr_pmu_caps, sizeof(char *));
if (!*caps)
return -1;
return 0;
}
- pmu_caps = zalloc(sizeof(*pmu_caps) * nr_pmu);
+ pmu_caps = calloc(nr_pmu, sizeof(*pmu_caps));
if (!pmu_caps)
return -ENOMEM;
nra = env->nr_cpus_avail;
nr = env->nr_cpus_online;
- cd_map = zalloc(sizeof(*cd_map) * nra);
+ cd_map = calloc(nra, sizeof(*cd_map));
if (!cd_map)
return -1;
cd_map[cpu]->nr_domains = nr_domains;
- cd_map[cpu]->domains = zalloc(sizeof(*d_info) * max_sched_domains);
+ cd_map[cpu]->domains = calloc(max_sched_domains, sizeof(*d_info));
if (!cd_map[cpu]->domains)
return -1;
* cumulated only one time to prevent entries more than 100%
* overhead.
*/
- he_cache = malloc(sizeof(*he_cache) * (cursor->nr + 1));
+ he_cache = calloc(cursor->nr + 1, sizeof(*he_cache));
if (he_cache == NULL)
return -ENOMEM;
max += bitmap_weight(n->set, n->size);
}
- entries = zalloc(sizeof(*entries) * max);
+ entries = calloc(max, sizeof(*entries));
if (!entries)
return -ENOMEM;
while ((pmu = scan_fn(pmu)) != NULL)
len += perf_pmu__num_events(pmu);
- aliases = zalloc(sizeof(struct sevent) * len);
+ aliases = calloc(len, sizeof(struct sevent));
if (!aliases) {
pr_err("FATAL: not enough memory to print PMU events\n");
return;
*/
#include <linux/string.h>
+#include <linux/zalloc.h>
#include <errno.h>
#include <inttypes.h>
#include "color.h"
/* Copy arguments and ensure return probe has no C argument */
pev->nargs = argc - 1;
- pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ pev->args = calloc(pev->nargs, sizeof(struct perf_probe_arg));
if (pev->args == NULL) {
ret = -ENOMEM;
goto out;
}
tev->nargs = argc - 2;
- tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
+ tev->args = calloc(tev->nargs, sizeof(struct probe_trace_arg));
if (tev->args == NULL) {
ret = -ENOMEM;
goto out;
/* Convert trace_arg to probe_arg */
pev->nargs = tev->nargs;
- pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+ pev->args = calloc(pev->nargs, sizeof(struct perf_probe_arg));
if (pev->args == NULL)
return -ENOMEM;
for (i = 0; i < tev->nargs && ret >= 0; i++) {
if (perf_probe_point__copy(&dst->point, &src->point) < 0)
goto out_err;
- dst->args = zalloc(sizeof(struct perf_probe_arg) * src->nargs);
+ dst->args = calloc(src->nargs, sizeof(struct perf_probe_arg));
if (!dst->args)
goto out_err;
dst->nargs = src->nargs;
}
/* Setup result trace-probe-events */
- *tevs = zalloc(sizeof(*tev) * num_matched_functions);
+ *tevs = calloc(num_matched_functions, sizeof(*tev));
if (!*tevs) {
ret = -ENOMEM;
goto out;
tev->uprobes = pev->uprobes;
tev->nargs = pev->nargs;
if (tev->nargs) {
- tev->args = zalloc(sizeof(struct probe_trace_arg) *
- tev->nargs);
+ tev->args = calloc(tev->nargs, sizeof(struct probe_trace_arg));
if (tev->args == NULL)
goto nomem_out;
}
}
tev->nargs = pev->nargs;
- tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
+ tev->args = calloc(tev->nargs, sizeof(struct probe_trace_arg));
if (!tev->args)
goto errout;
goto out;
}
- *tevs = zalloc(ret * sizeof(*tev));
+ *tevs = calloc(ret, sizeof(*tev));
if (!*tevs) {
ret = -ENOMEM;
goto out;
if (ret > probe_conf.max_probes)
return -E2BIG;
- *tevs = zalloc(ret * sizeof(*tev));
+ *tevs = calloc(ret, sizeof(*tev));
if (!*tevs)
return -ENOMEM;
tev->point.offset);
/* Expand special probe argument if exist */
- args = zalloc(sizeof(struct perf_probe_arg) * MAX_PROBE_ARGS);
+ args = calloc(MAX_PROBE_ARGS, sizeof(struct perf_probe_arg));
if (args == NULL) {
ret = -ENOMEM;
goto end;
goto end;
tev->nargs = ret;
- tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
+ tev->args = calloc(tev->nargs, sizeof(struct probe_trace_arg));
if (tev->args == NULL) {
ret = -ENOMEM;
goto end;
int ret, i;
/* Allocate result tevs array */
- *tevs = zalloc(sizeof(struct probe_trace_event) * tf.max_tevs);
+ *tevs = calloc(tf.max_tevs, sizeof(struct probe_trace_event));
if (*tevs == NULL)
return -ENOMEM;
int ret;
/* Allocate result vls array */
- *vls = zalloc(sizeof(struct variable_list) * af.max_vls);
+ *vls = calloc(af.max_vls, sizeof(struct variable_list));
if (*vls == NULL)
return -ENOMEM;
nr_readers++;
}
- rd = zalloc(nr_readers * sizeof(struct reader));
+ rd = calloc(nr_readers, sizeof(struct reader));
if (!rd)
return -ENOMEM;
#include <inttypes.h>
#include <string.h>
#include <linux/string.h>
+#include <linux/zalloc.h>
bool srcline_full_filename;
#include "metricgroup.h"
#include "cgroup.h"
#include "units.h"
-#include <linux/zalloc.h>
#include "iostat.h"
#include "util/hashmap.h"
#include "tool_pmu.h"
#include <unistd.h>
#include <sys/mman.h>
#include <linux/list.h>
-#include <linux/zalloc.h>
#ifndef REMOTE_UNWIND_LIBUNWIND
#include <libunwind.h>
#include <libunwind-ptrace.h>
int perf_read_values_init(struct perf_read_values *values)
{
values->threads_max = 16;
- values->pid = malloc(values->threads_max * sizeof(*values->pid));
- values->tid = malloc(values->threads_max * sizeof(*values->tid));
- values->value = zalloc(values->threads_max * sizeof(*values->value));
+ values->pid = calloc(values->threads_max, sizeof(*values->pid));
+ values->tid = calloc(values->threads_max, sizeof(*values->tid));
+ values->value = calloc(values->threads_max, sizeof(*values->value));
if (!values->pid || !values->tid || !values->value) {
pr_debug("failed to allocate read_values threads arrays");
goto out_free_pid;
i = values->threads;
- values->value[i] = zalloc(values->counters_max * sizeof(**values->value));
+ values->value[i] = calloc(values->counters_max, sizeof(**values->value));
if (!values->value[i]) {
pr_debug("failed to allocate read_values counters array");
return -ENOMEM;