From: Nathan F. <nf...@li...> - 2015-06-23 13:35:57
|
Use calloc instead of malloc + memset for array allocation. Signed-off-by: Nathan Fontenot <nf...@li...> --- src/ppc64_cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ppc64_cpu.c b/src/ppc64_cpu.c index 6ecfe7f..42994ca 100644 --- a/src/ppc64_cpu.c +++ b/src/ppc64_cpu.c @@ -980,8 +980,9 @@ static int do_cpu_frequency(int sleep_time) setrlimit_open_files(); - cpu_freqs = malloc(sizeof(*cpu_freqs) * threads_in_system); - memset(cpu_freqs, 0, sizeof(*cpu_freqs) * threads_in_system); + cpu_freqs = calloc(threads_in_system, sizeof(*cpu_freqs)); + if (!cpu_freqs) + return -ENOMEM; rc = setup_counters(cpu_freqs); if (rc) { @@ -1123,8 +1124,10 @@ static int do_cores_online(char *state) return -1; } - core_state = malloc(sizeof(int) * cpus_in_system); - memset(core_state, 0, sizeof(int) * cpus_in_system); + core_state = calloc(cpus_in_system, sizeof(int)); + if (!core_state) + return -ENOMEM; + for (i = 0; i < cpus_in_system ; i++) { core_state[i] = cpu_online(i * threads_per_cpu); if (core_state[i]) |