perf tools: Fix calloc() arguments to address error introduced in gcc-14 24/314724/1
authorSun Haiyong <sunhaiyong@loongson.cn>
Sat, 6 Jan 2024 09:41:29 +0000 (17:41 +0800)
committerJaehoon Chung <jh80.chung@samsung.com>
Thu, 18 Jul 2024 06:33:25 +0000 (15:33 +0900)
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>
[cherry picked from commit 7bbe8f0071dfa23fcc3b2864ec9f3b1aeb7ab2df]
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Change-Id: I33ad62e8acc5fde24b9bf355c137f67a43a29067

tools/perf/builtin-record.c
tools/perf/util/hist.c
tools/perf/util/metricgroup.c
tools/perf/util/synthetic-events.c

index 59f3d98a0196d1cf80250214ddc2e1f8dc292a8f..e6795f538468a4726e9bad09e34a433bc64755a9 100644 (file)
@@ -4073,8 +4073,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;
index 17a05e943b44b5f7234719e5e3c87f82ff58ec67..2b96ba7f350df4250d605470e347319c805ae8c0 100644 (file)
@@ -489,8 +489,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;
        }
index 4c98ac29ee13feb7710bf1dd95ad49e40ca75ade..af6377eebb55cc0cbcf1a4dd3b8fc81eb945e111 100644 (file)
@@ -266,7 +266,7 @@ static int setup_metric_events(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;
 
index cccd293b531246eba4cf3150676ecbd141235594..fb9a4cabb228acc5e8a30bc243b3888874b5d07b 100644 (file)
@@ -1037,11 +1037,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;