Commit 7bbe8f00 authored by Sun Haiyong's avatar Sun Haiyong Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarSun Haiyong <sunhaiyong@loongson.cn>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarArnaldo 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: default avatarYanteng Si <siyanteng@loongson.cn>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 79baac8a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4080,8 +4080,8 @@ int cmd_record(int argc, const char **argv)
	}

	if (rec->switch_output.num_files) {
		rec->switch_output.filenames = calloc(sizeof(char *),
						      rec->switch_output.num_files);
		rec->switch_output.filenames = calloc(rec->switch_output.num_files,
						      sizeof(char *));
		if (!rec->switch_output.filenames) {
			err = -EINVAL;
			goto out_opts;
+2 −2
Original line number Diff line number Diff line
@@ -491,8 +491,8 @@ static int hist_entry__init(struct hist_entry *he,
	}

	if (symbol_conf.res_sample) {
		he->res_samples = calloc(sizeof(struct res_sample),
					symbol_conf.res_sample);
		he->res_samples = calloc(symbol_conf.res_sample,
					sizeof(struct res_sample));
		if (!he->res_samples)
			goto err_srcline;
	}
+1 −1
Original line number Diff line number Diff line
@@ -286,7 +286,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
	*out_metric_events = NULL;
	ids_size = hashmap__size(ids);

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

+2 −2
Original line number Diff line number Diff line
@@ -1055,11 +1055,11 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
	if (thread_nr > n)
		thread_nr = n;

	synthesize_threads = calloc(sizeof(pthread_t), thread_nr);
	synthesize_threads = calloc(thread_nr, sizeof(pthread_t));
	if (synthesize_threads == NULL)
		goto free_dirent;

	args = calloc(sizeof(*args), thread_nr);
	args = calloc(thread_nr, sizeof(*args));
	if (args == NULL)
		goto free_threads;