Skip to content

Commit 7bbe8f0

Browse files
Sun Haiyongacmel
authored andcommitted
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>
1 parent 79baac8 commit 7bbe8f0

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

tools/perf/builtin-record.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,8 +4080,8 @@ int cmd_record(int argc, const char **argv)
40804080
}
40814081

40824082
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 *));
40854085
if (!rec->switch_output.filenames) {
40864086
err = -EINVAL;
40874087
goto out_opts;

tools/perf/util/hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ static int hist_entry__init(struct hist_entry *he,
491491
}
492492

493493
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));
496496
if (!he->res_samples)
497497
goto err_srcline;
498498
}

tools/perf/util/metricgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
286286
*out_metric_events = NULL;
287287
ids_size = hashmap__size(ids);
288288

289-
metric_events = calloc(sizeof(void *), ids_size + 1);
289+
metric_events = calloc(ids_size + 1, sizeof(void *));
290290
if (!metric_events)
291291
return -ENOMEM;
292292

tools/perf/util/synthetic-events.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,11 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
10551055
if (thread_nr > n)
10561056
thread_nr = n;
10571057

1058-
synthesize_threads = calloc(sizeof(pthread_t), thread_nr);
1058+
synthesize_threads = calloc(thread_nr, sizeof(pthread_t));
10591059
if (synthesize_threads == NULL)
10601060
goto free_dirent;
10611061

1062-
args = calloc(sizeof(*args), thread_nr);
1062+
args = calloc(thread_nr, sizeof(*args));
10631063
if (args == NULL)
10641064
goto free_threads;
10651065

0 commit comments

Comments
 (0)