From 804ae6bc91ae3e87fa96ce55ebf2be7f032a7ac4 Mon Sep 17 00:00:00 2001 From: Yunseong Kim Date: Thu, 20 Jun 2024 03:53:42 +0900 Subject: [PATCH] uftrace: Align exact argument on calloc Align argument for calloc call in some code and macro in utils.h file. Signed-off-by: Yunseong Kim --- cmds/info.c | 2 +- libmcount/record.c | 2 +- libmcount/wrap.c | 4 ++-- utils/kernel.c | 2 +- utils/utils.h | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmds/info.c b/cmds/info.c index ce69da836..12c573a8c 100644 --- a/cmds/info.c +++ b/cmds/info.c @@ -539,7 +539,7 @@ static int read_taskinfo(void *arg) else if (!strncmp(&buf[9], "tids=", 5)) { char *tids_str = &buf[14]; char *endp = tids_str; - int *tids = xcalloc(sizeof(*tids), info->nr_tid); + int *tids = xcalloc(info->nr_tid, sizeof(*tids)); int nr_tid = 0; while (*endp != '\n') { diff --git a/libmcount/record.c b/libmcount/record.c index 8d16ea6f0..2ff9f4b89 100644 --- a/libmcount/record.c +++ b/libmcount/record.c @@ -73,7 +73,7 @@ void prepare_shmem_buffer(struct mcount_thread_data *mtdp) shmem->nr_buf = 2; shmem->max_buf = 2; - shmem->buffer = xcalloc(sizeof(*shmem->buffer), 2); + shmem->buffer = xcalloc(2, sizeof(*shmem->buffer)); for (idx = 0; idx < shmem->nr_buf; idx++) { shmem->buffer[idx] = allocate_shmem_buffer(buf, sizeof(buf), tid, idx); diff --git a/libmcount/wrap.c b/libmcount/wrap.c index ba69e9c64..c52e91a1d 100644 --- a/libmcount/wrap.c +++ b/libmcount/wrap.c @@ -197,7 +197,7 @@ static char **collect_uftrace_envp(void) n++; } - envp = xcalloc(sizeof(*envp), n + 2); + envp = xcalloc(n + 2, sizeof(*envp)); for (i = k = 0; i < ARRAY_SIZE(uftrace_env); i++) { char *env_str; @@ -232,7 +232,7 @@ static char **merge_envp(char *const *env1, char **env2) n += count_envp(env1); n += count_envp(env2); - envp = xcalloc(sizeof(*envp), n + 1); + envp = xcalloc(n + 1, sizeof(*envp)); n = 0; for (i = 0; env1 && env1[i]; i++) diff --git a/utils/kernel.c b/utils/kernel.c index cd71a6a2a..626aea0bc 100644 --- a/utils/kernel.c +++ b/utils/kernel.c @@ -1778,7 +1778,7 @@ static int kernel_test_setup_handle(struct uftrace_kernel_reader *kernel, int i; handle->nr_tasks = NUM_TASK; - handle->tasks = xcalloc(sizeof(*handle->tasks), NUM_TASK); + handle->tasks = xcalloc(NUM_TASK, sizeof(*handle->tasks)); handle->time_range.start = handle->time_range.stop = 0; handle->time_filter = 0; diff --git a/utils/utils.h b/utils/utils.h index 20b2551cc..dd4a182be 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -190,16 +190,16 @@ extern void setup_signal(void); #define xzalloc(sz) \ ({ \ - void *__ptr = calloc(sz, 1); \ + void *__ptr = calloc(1, sz); \ if (__ptr == NULL) { \ pr_err("xzalloc"); \ } \ __ptr; \ }) -#define xcalloc(sz, n) \ +#define xcalloc(n, sz) \ ({ \ - void *__ptr = calloc(sz, n); \ + void *__ptr = calloc(n, sz); \ if (__ptr == NULL) { \ pr_err("xcalloc"); \ } \