]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf tools: Use calloc() where applicable
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Apr 2026 17:32:02 +0000 (14:32 -0300)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 9 Apr 2026 02:21:05 +0000 (19:21 -0700)
Instead of using zalloc(nr_entries * sizeof_entry) that is what calloc()
does.

In some places where linux/zalloc.h isn't needed, remove it, add when
needed and was getting it indirectly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
42 files changed:
tools/perf/arch/arm/util/auxtrace.c
tools/perf/arch/powerpc/util/auxtrace.c
tools/perf/arch/x86/tests/amd-ibs-period.c
tools/perf/arch/x86/tests/dwarf-unwind.c
tools/perf/arch/x86/util/pmu.c
tools/perf/bench/numa.c
tools/perf/bench/sched-messaging.c
tools/perf/builtin-annotate.c
tools/perf/builtin-c2c.c
tools/perf/builtin-diff.c
tools/perf/builtin-ftrace.c
tools/perf/builtin-kwork.c
tools/perf/builtin-record.c
tools/perf/builtin-sched.c
tools/perf/builtin-script.c
tools/perf/builtin-stat.c
tools/perf/builtin-trace.c
tools/perf/jvmti/libjvmti.c
tools/perf/tests/code-reading.c
tools/perf/tests/thread-map.c
tools/perf/util/annotate-arch/annotate-x86.c
tools/perf/util/bpf-event.c
tools/perf/util/bpf_counter_cgroup.c
tools/perf/util/data-convert-bt.c
tools/perf/util/data.c
tools/perf/util/db-export.c
tools/perf/util/disasm.c
tools/perf/util/event.c
tools/perf/util/evlist.c
tools/perf/util/header.c
tools/perf/util/hist.c
tools/perf/util/mem2node.c
tools/perf/util/pmus.c
tools/perf/util/powerpc-vpadtl.c
tools/perf/util/probe-event.c
tools/perf/util/probe-file.c
tools/perf/util/probe-finder.c
tools/perf/util/session.c
tools/perf/util/srcline.c
tools/perf/util/stat-shadow.c
tools/perf/util/unwind-libunwind-local.c
tools/perf/util/values.c

index eb6404267f1715a9ff57cd48e0e34783a27b54b0..27bb14c8b880068a22b85a863664efa7eea18bd8 100644 (file)
@@ -8,7 +8,7 @@
 #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"
@@ -27,7 +27,7 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
        /* 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;
@@ -79,7 +79,7 @@ static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_ptts, int *err)
        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;
index 292ea335e4fff6b9dce1315665ee39d1a393ded4..e39deff6c857a82ac4b5c9ee653f7d68bba54dae 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/string.h>
+#include <linux/zalloc.h>
 
 #include "../../util/evlist.h"
 #include "../../util/debug.h"
index 223e059e04deb005f564b6beec5539dc4cc700e9..cee9e11c05e08c094e723f04ad22f846e5c745b1 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "arch-tests.h"
 #include "linux/perf_event.h"
-#include "linux/zalloc.h"
 #include "tests/tests.h"
 #include "../perf-sys.h"
 #include "pmu.h"
@@ -60,7 +59,7 @@ static int dummy_workload_1(unsigned long count)
                0xcc, /* int 3 */
        };
 
-       p = zalloc(2 * page_size);
+       p = calloc(2, page_size);
        if (!p) {
                printf("malloc() failed. %m");
                return 1;
index e91a73d09cecfd83d3595d6a19a447ae50c2d1ef..99d2b7ed016fd63fb9d5d86f47f2741a38b9be98 100644 (file)
@@ -54,22 +54,13 @@ int test__arch_unwind_sample(struct perf_sample *sample,
                             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;
index 0661e0f0b02d03cd6f8992834a2168044564ce9a..7c9d238922a6ce57dcb49ade042bbab9a8abd80d 100644 (file)
@@ -7,7 +7,6 @@
 #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>
index 6588a9b0b15aec6dca22a108f8143def50aab332..42d7afc03f9b9ed203e37fe4f5c07ddb20c4c53a 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/kernel.h>
 #include <linux/time64.h>
 #include <linux/numa.h>
-#include <linux/zalloc.h>
 
 #include "../util/header.h"
 #include "../util/mutex.h"
@@ -980,10 +979,8 @@ static int count_process_nodes(int process_nr)
        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;
@@ -1090,10 +1087,8 @@ static void calc_convergence(double runtime_ns_max, double *convergence)
        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;
@@ -1423,7 +1418,7 @@ static void worker_process(int process_nr)
        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) {
@@ -1629,7 +1624,7 @@ static int __bench_numa(const char *name)
        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) {
index 93dcd9dba3d0dcb291b17b86a25fe411b3ddfb26..4fb6657fc826c76c702706fb0a9f5486170cd6f4 100644 (file)
@@ -301,7 +301,7 @@ int bench_sched_messaging(int argc, const char **argv)
        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()");
 
index 530348b6981b73bed9ba91f5445e8ebe7644e2ef..5e57b78548f4210d26230eec3688d372141dd5ac 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/list.h>
 #include "util/cache.h"
 #include <linux/rbtree.h>
-#include <linux/zalloc.h>
 #include "util/symbol.h"
 
 #include "util/debug.h"
index 3ce5f0adec2f31c21c106391e6a816fd4ad2cfc0..72a7802775ee965fec74bfa82bf74f2a65cead20 100644 (file)
@@ -155,7 +155,7 @@ static void *c2c_he_zalloc(size_t size)
        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;
 
@@ -2324,13 +2324,13 @@ static int setup_nodes(struct perf_session *session)
        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;
 
index 2c59e43901fe54254ec603517991452897d8abb0..1b3df868849a99c0af986cf04461521439c4e906 100644 (file)
@@ -1891,7 +1891,7 @@ static int data_init(int argc, const char **argv)
                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;
 
index 4cc33452d79b626b0d6958177d1acbac121cdbbd..8a7dbfb14535e2ba328da745a7227fc9aa1a6af8 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/capability.h>
 #include <linux/err.h>
 #include <linux/string.h>
+#include <linux/zalloc.h>
 #include <sys/stat.h>
 
 #include "debug.h"
index 1140e00e874f4eed424ef533b367e5d962a9c14b..9d3a4c779a41e383f8321d1a151fc09712f38712 100644 (file)
@@ -2208,7 +2208,7 @@ static int perf_kwork__top(struct perf_kwork *kwork)
        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;
 
index e919d1f021c3cdbfbf780b3acac8c4fe8c561317..1adc37b451528798ffa2907724f3c0f5c96a2040 100644 (file)
@@ -1070,12 +1070,12 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
                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;
@@ -1220,7 +1220,7 @@ static int record__alloc_thread_data(struct record *rec, struct evlist *evlist)
        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;
@@ -3710,7 +3710,7 @@ static int record__alloc_thread_masks(struct record *rec, int nr_threads, int nr
 {
        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;
@@ -3920,7 +3920,7 @@ static int record__init_thread_numa_masks(struct record *rec, struct perf_cpu_ma
                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;
index 9fb5447f9014d0264f3de0047ad299ff1a67f12f..555247568e7a611000af5dcb9f35cdc8ebf1fe31 100644 (file)
@@ -2405,7 +2405,7 @@ static int init_idle_threads(int ncpu)
 {
        int i, ret;
 
-       idle_threads = zalloc(ncpu * sizeof(struct thread *));
+       idle_threads = calloc(ncpu, sizeof(struct thread *));
        if (!idle_threads)
                return -ENOMEM;
 
@@ -3483,7 +3483,7 @@ static int setup_cpus_switch_event(struct perf_sched *sched)
        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;
@@ -3559,7 +3559,7 @@ static int setup_map_cpus(struct perf_sched *sched)
        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;
        }
index 43ce119dac3ed9f9fb7b214ec74ccf0f33f0e7a3..c8ac9f01a36bc51145e8ef94d1ca1af8366fe4b5 100644 (file)
@@ -3823,7 +3823,7 @@ out:
 
 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");
@@ -4312,7 +4312,7 @@ int cmd_script(int argc, const char **argv)
                                }
                        }
 
-                       __argv = malloc((argc + 6) * sizeof(const char *));
+                       __argv = calloc(argc + 6, sizeof(const char *));
                        if (!__argv) {
                                pr_err("malloc failed\n");
                                err = -ENOMEM;
@@ -4338,7 +4338,7 @@ int cmd_script(int argc, const char **argv)
                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;
@@ -4376,7 +4376,7 @@ script_found:
                        }
                }
 
-               __argv = malloc((argc + 2) * sizeof(const char *));
+               __argv = calloc(argc + 2, sizeof(const char *));
                if (!__argv) {
                        pr_err("malloc failed\n");
                        err = -ENOMEM;
index 35934e8bbd5199b4114fb25251b44269c7eb910f..99d7db372b480800096d9eb9084748af3bf102ea 100644 (file)
@@ -2774,7 +2774,7 @@ int cmd_stat(int argc, const char **argv)
        }
 
        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;
index 873d144807e2d16a3dde5b1ec9255bb5d9d9272d..e58c49d047a294db3af61ca6f71173e0de5a25aa 100644 (file)
@@ -2269,9 +2269,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)
        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);
index 87bfd4781003a331781923d192da1f0875269abd..d3dc53010e768669c67efb227ba17552e4e0cb49 100644 (file)
@@ -98,7 +98,7 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, jvmti_line_info_t **
        /*
         * 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;
 
@@ -262,11 +262,10 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
                        }
                        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");
index 5927d1ea20e2233145c478d6a443fb83a186b3d4..47043a3a2fb4f833132497403eb31e385ce8a088 100644 (file)
@@ -4,6 +4,7 @@
 #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>
index 54209592168d8aaf01de031eac82f02ea61349ed..877868107455e87e526e2b336ca1ca3c7314033e 100644 (file)
@@ -9,7 +9,6 @@
 #include "debug.h"
 #include "event.h"
 #include "util/synthetic-events.h"
-#include <linux/zalloc.h>
 #include <perf/event.h>
 #include <internal/threadmap.h>
 
index c77aabd48ebab69364e19ac52b81b203b663e4f5..7e61365363938728b9bde5ac057ba8d9f66bc03c 100644 (file)
@@ -1,6 +1,7 @@
 // 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"
index 67e7786bb878b39661d42948d52ac206c57bd3b8..a27945c279efb7791350a08726e5455c30e7bb8c 100644 (file)
@@ -349,7 +349,7 @@ static struct bpf_metadata *bpf_metadata_alloc(__u32 nr_prog_tags,
        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;
index 5572ceccf86092ff9e235881e869fb9749258ff7..519fee3dc3d03685118f095706fff1ac3a7554c5 100644 (file)
@@ -11,7 +11,6 @@
 #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>
index bece77cbc49361b4b03d56bf586fa75b1bfdf7cc..3b8f2df823a9b7900997e7a6061f6a78d5fc84b5 100644 (file)
@@ -1379,7 +1379,7 @@ static int setup_streams(struct ctf_writer *cw, struct perf_session *session)
         */
        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;
index 90df41da1a32b315a5e0097f29f27a522873e3ef..14fa83dae71a8b80b8d3eb654bd4611fd9fe4b8d 100644 (file)
@@ -43,7 +43,7 @@ int perf_data__create_dir(struct perf_data *data, int nr)
        if (WARN_ON(!data->is_dir))
                return -EINVAL;
 
-       files = zalloc(nr * sizeof(*files));
+       files = calloc(nr, sizeof(*files));
        if (!files)
                return -ENOMEM;
 
index ae9a9065aab76c63fd59a93184201a2178811c2d..cc2bb1af4243446c4424cde04b1e7a0a0b33dde1 100644 (file)
@@ -19,7 +19,6 @@
 #include "callchain.h"
 #include "call-path.h"
 #include "db-export.h"
-#include <linux/zalloc.h>
 
 int db_export__init(struct db_export *dbe)
 {
index 40fcaed5d0b1a3b8df0a6ccce8805b5261c9c34a..4f5bd915355242ec7d4f7990b83169be08042aa2 100644 (file)
@@ -13,6 +13,7 @@
 #include <unistd.h>
 
 #include <linux/string.h>
+#include <linux/zalloc.h>
 #include <subcmd/run-command.h>
 
 #include "annotate.h"
index bc045fddf7d57569b00789aff92e69a57c846ae7..66f4843bb235df5365a08c8553ac567b8f5ba0d3 100644 (file)
@@ -12,7 +12,6 @@
 #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"
index f46e1d40bad7324c8e47f6d972fa7dcc20abab41..ee971d15b3c66bc146ad72f21981a08c485717f1 100644 (file)
@@ -825,9 +825,8 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
                                       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;
 
index 4925e33778b913130cca0f0e72fe5311ede8522c..c6efddb70aee29049f6722efd630db8fa457f462 100644 (file)
@@ -2816,7 +2816,7 @@ static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused)
        if (!cmdline)
                return -1;
 
-       argv = zalloc(sizeof(char *) * (nr + 1));
+       argv = calloc(nr + 1, sizeof(char *));
        if (!argv)
                goto error;
 
@@ -2970,7 +2970,7 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)
        if (do_read_u32(ff, &nr))
                return -1;
 
-       nodes = zalloc(sizeof(*nodes) * nr);
+       nodes = calloc(nr, sizeof(*nodes));
        if (!nodes)
                return -ENOMEM;
 
@@ -3168,7 +3168,7 @@ static int process_cache(struct feat_fd *ff, void *data __maybe_unused)
        if (do_read_u32(ff, &cnt))
                return -1;
 
-       caches = zalloc(sizeof(*caches) * cnt);
+       caches = calloc(cnt, sizeof(*caches));
        if (!caches)
                return -1;
 
@@ -3260,7 +3260,7 @@ static int process_mem_topology(struct feat_fd *ff,
        if (do_read_u64(ff, &nr))
                return -1;
 
-       nodes = zalloc(sizeof(*nodes) * nr);
+       nodes = calloc(nr, sizeof(*nodes));
        if (!nodes)
                return -1;
 
@@ -3350,7 +3350,7 @@ static int process_hybrid_topology(struct feat_fd *ff,
        if (do_read_u32(ff, &nr))
                return -1;
 
-       nodes = zalloc(sizeof(*nodes) * nr);
+       nodes = calloc(nr, sizeof(*nodes));
        if (!nodes)
                return -ENOMEM;
 
@@ -3565,7 +3565,7 @@ static int __process_pmu_caps(struct feat_fd *ff, int *nr_caps,
        if (!nr_pmu_caps)
                return 0;
 
-       *caps = zalloc(sizeof(char *) * nr_pmu_caps);
+       *caps = calloc(nr_pmu_caps, sizeof(char *));
        if (!*caps)
                return -1;
 
@@ -3642,7 +3642,7 @@ static int process_pmu_caps(struct feat_fd *ff, void *data __maybe_unused)
                return 0;
        }
 
-       pmu_caps = zalloc(sizeof(*pmu_caps) * nr_pmu);
+       pmu_caps = calloc(nr_pmu, sizeof(*pmu_caps));
        if (!pmu_caps)
                return -ENOMEM;
 
@@ -3695,7 +3695,7 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused
        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;
 
@@ -3733,7 +3733,7 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused
 
                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;
 
index fc737a0a8e4d7acd94284a51e2adc7bce4e0e1d5..747fdc455c80ec0fc3ab0d90a01ca9741f9040e4 100644 (file)
@@ -1151,7 +1151,7 @@ iter_prepare_cumulative_entry(struct hist_entry_iter *iter,
         * 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;
 
index 03a7d7b2773774a0775fe3a6706d5bb029b711cc..51a2292cbf7ef44fc50e1145cf39c84a9f0b2a37 100644 (file)
@@ -59,7 +59,7 @@ int mem2node__init(struct mem2node *map, struct perf_env *env)
                max += bitmap_weight(n->set, n->size);
        }
 
-       entries = zalloc(sizeof(*entries) * max);
+       entries = calloc(max, sizeof(*entries));
        if (!entries)
                return -ENOMEM;
 
index 98be2eb8f1f03923d36ad4f022bb8f28a6eb6072..9a2023ceeefd933a960976a5de723e2016fea060 100644 (file)
@@ -621,7 +621,7 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p
        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;
index 993ab16614c7285ffcf1f856c4f6ac8db3fcf9dc..710f3093f3f909c423ae22c7636065fcf3469eb8 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/string.h>
+#include <linux/zalloc.h>
 #include <errno.h>
 #include <inttypes.h>
 #include "color.h"
index 710e4620923ea8b2bfe40d21a7028d91c174f7d5..f37a783ea7723197014c09afd580d6470f2e5583 100644 (file)
@@ -1850,7 +1850,7 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
 
        /* 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;
@@ -2000,7 +2000,7 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
        }
 
        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;
@@ -2373,7 +2373,7 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
 
        /* 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++) {
@@ -2480,7 +2480,7 @@ int perf_probe_event__copy(struct perf_probe_event *dst,
        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;
@@ -3179,7 +3179,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
        }
 
        /* 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;
@@ -3251,8 +3251,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
                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;
                }
@@ -3363,7 +3362,7 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
        }
 
        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;
 
@@ -3549,7 +3548,7 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
                goto out;
        }
 
-       *tevs = zalloc(ret * sizeof(*tev));
+       *tevs = calloc(ret, sizeof(*tev));
        if (!*tevs) {
                ret = -ENOMEM;
                goto out;
index f78c3bc3d601ea958f031447846bdd888f30baad..4032572cbf55df127c3ddad301267bb5803f839f 100644 (file)
@@ -414,7 +414,7 @@ int probe_cache_entry__get_event(struct probe_cache_entry *entry,
        if (ret > probe_conf.max_probes)
                return -E2BIG;
 
-       *tevs = zalloc(ret * sizeof(*tev));
+       *tevs = calloc(ret, sizeof(*tev));
        if (!*tevs)
                return -ENOMEM;
 
index 5ffd97ee4898e51eee1d6a51de930a4e25432320..64328abeef8b24276584363259d146b832ad866b 100644 (file)
@@ -1305,7 +1305,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf)
                 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;
@@ -1316,7 +1316,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf)
                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;
@@ -1393,7 +1393,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
        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;
 
@@ -1566,7 +1566,7 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg,
        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;
 
index 7588cca110d2b08f64e1515f911f8e223eb2820b..312ea05e21139213e2c13793e967bf5e774a6bdc 100644 (file)
@@ -2559,7 +2559,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)
                        nr_readers++;
        }
 
-       rd = zalloc(nr_readers * sizeof(struct reader));
+       rd = calloc(nr_readers, sizeof(struct reader));
        if (!rd)
                return -ENOMEM;
 
index 9be42f3984405f9edd15836a7e8173aa1ec26a33..b58710624eadfe1b7a4a4a7a58db34e9b410b638 100644 (file)
@@ -12,6 +12,7 @@
 #include <inttypes.h>
 #include <string.h>
 #include <linux/string.h>
+#include <linux/zalloc.h>
 
 bool srcline_full_filename;
 
index 59d2cd4f2188de72aacb751e8b1b34ce5f8b9a33..bc2d44df7bafa4d55354b379d515490b76bf4d41 100644 (file)
@@ -13,7 +13,6 @@
 #include "metricgroup.h"
 #include "cgroup.h"
 #include "units.h"
-#include <linux/zalloc.h>
 #include "iostat.h"
 #include "util/hashmap.h"
 #include "tool_pmu.h"
index 5b39ce21e33351f8ac01df501d8ba8b19b0f57d5..87d496e9dfa6669cb80c045ba036be6f39bf2038 100644 (file)
@@ -25,7 +25,6 @@
 #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>
index ec72d29f3d586d47f6025e13ae8cda3a39a79b84..6eaddfcf833e52a20ae72f0ec706e79eca9e0be7 100644 (file)
@@ -13,9 +13,9 @@
 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;
@@ -96,7 +96,7 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values,
 
        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;