From a8d328bba2806baabaf70364b7f133dcd6ca8b59 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Thu, 25 May 2023 12:25:12 +0200 Subject: [PATCH] cpumf/lshwc: replace memory alloction functions by library counterparts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace memory allocation functions malloc() and calloc() by counterparts provided in libutil.a library. Also remove error handling when no memory could be allocated as those functions do not return. Signed-off-by: Thomas Richter Acked-by: Sumanth Korikkar Signed-off-by: Jan Höppner --- cpumf/lshwc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cpumf/lshwc.c b/cpumf/lshwc.c index 328cd135..897529f9 100644 --- a/cpumf/lshwc.c +++ b/cpumf/lshwc.c @@ -276,9 +276,7 @@ static bool check_setpossible(void) if (!get_cpus(CPUS_KERNELMAX, cpubuf, sizeof(cpubuf))) return false; max_possible_cpus = getnumber(cpubuf, '\0') + 1; - check = calloc(max_possible_cpus, sizeof(*check)); - if (!check) - err(EXIT_FAILURE, "Maximum CPUs %u", max_possible_cpus); + check = util_zalloc(max_possible_cpus * sizeof(*check)); if (!get_cpus(CPUS_POSSIBLE, cpubuf, sizeof(cpubuf))) { free(check); return false; @@ -533,13 +531,8 @@ static int do_read(int ioctlfd) struct s390_hwctr_read *read; int rc; - if (!ioctlbuffer) { - ioctlbuffer = malloc(ioctlbuffer_len); - if (!ioctlbuffer) { - warn("ioctl S390_HWCTR_START"); - return -ENOMEM; - } - } + if (!ioctlbuffer) + ioctlbuffer = util_malloc(ioctlbuffer_len); read = (struct s390_hwctr_read *)ioctlbuffer; rc = ioctl(ioctlfd, S390_HWCTR_READ, read); if (!rc)