Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix calloc() arguments to address error introduced in gcc-14

the definition of calloc is as follows:

void *calloc(size_t nmemb, size_t size);

number of members is in the first parameter and the size is in the
second parameter.

Fix error messages on gcc 14 20240102:

error: 'calloc' sizes specified with 'sizeof' in the earlier argument and
not in the later argument [-Werror=calloc-transposed-args]

Committer notes:

I noticed this on fedora 40 and rawhide.

Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240106094129.3337057-1-siyanteng@loongson.cn
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Sun Haiyong and committed by
Arnaldo Carvalho de Melo
7bbe8f00 79baac8a

+7 -7
+2 -2
tools/perf/builtin-record.c
··· 4080 4080 } 4081 4081 4082 4082 if (rec->switch_output.num_files) { 4083 - rec->switch_output.filenames = calloc(sizeof(char *), 4084 - rec->switch_output.num_files); 4083 + rec->switch_output.filenames = calloc(rec->switch_output.num_files, 4084 + sizeof(char *)); 4085 4085 if (!rec->switch_output.filenames) { 4086 4086 err = -EINVAL; 4087 4087 goto out_opts;
+2 -2
tools/perf/util/hist.c
··· 491 491 } 492 492 493 493 if (symbol_conf.res_sample) { 494 - he->res_samples = calloc(sizeof(struct res_sample), 495 - symbol_conf.res_sample); 494 + he->res_samples = calloc(symbol_conf.res_sample, 495 + sizeof(struct res_sample)); 496 496 if (!he->res_samples) 497 497 goto err_srcline; 498 498 }
+1 -1
tools/perf/util/metricgroup.c
··· 286 286 *out_metric_events = NULL; 287 287 ids_size = hashmap__size(ids); 288 288 289 - metric_events = calloc(sizeof(void *), ids_size + 1); 289 + metric_events = calloc(ids_size + 1, sizeof(void *)); 290 290 if (!metric_events) 291 291 return -ENOMEM; 292 292
+2 -2
tools/perf/util/synthetic-events.c
··· 1055 1055 if (thread_nr > n) 1056 1056 thread_nr = n; 1057 1057 1058 - synthesize_threads = calloc(sizeof(pthread_t), thread_nr); 1058 + synthesize_threads = calloc(thread_nr, sizeof(pthread_t)); 1059 1059 if (synthesize_threads == NULL) 1060 1060 goto free_dirent; 1061 1061 1062 - args = calloc(sizeof(*args), thread_nr); 1062 + args = calloc(thread_nr, sizeof(*args)); 1063 1063 if (args == NULL) 1064 1064 goto free_threads; 1065 1065