Commit f5f30386 authored by Tiezhu Yang's avatar Tiezhu Yang Committed by Alexei Starovoitov

bpftool: Silence build warning about calloc()

There exists the following warning when building bpftool:

  CC      prog.o
prog.c: In function ‘profile_open_perf_events’:
prog.c:2301:24: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
 2301 |                 sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric);
      |                        ^~~
prog.c:2301:24: note: earlier argument should specify number of elements, later size of each element

Tested with the latest upstream GCC which contains a new warning option
-Wcalloc-transposed-args. The first argument to calloc is documented to
be number of elements in array, while the second argument is size of each
element, just switch the first and second arguments of calloc() to silence
the build warning, compile tested only.

Fixes: 47c09d6a ("bpftool: Introduce "prog profile" command")
Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20240116061920.31172-1-yangtiezhu@loongson.cnSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 49c06547
...@@ -2298,7 +2298,7 @@ static int profile_open_perf_events(struct profiler_bpf *obj) ...@@ -2298,7 +2298,7 @@ static int profile_open_perf_events(struct profiler_bpf *obj)
int map_fd; int map_fd;
profile_perf_events = calloc( profile_perf_events = calloc(
sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric); obj->rodata->num_cpu * obj->rodata->num_metric, sizeof(int));
if (!profile_perf_events) { if (!profile_perf_events) {
p_err("failed to allocate memory for perf_event array: %s", p_err("failed to allocate memory for perf_event array: %s",
strerror(errno)); strerror(errno));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment