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

libbpf: Fix warning in calloc() usage

When compiling libbpf with some compilers, this warning is triggered:

libbpf.c: In function ‘bpf_object__gen_loader’:
libbpf.c:9209:28: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
9209 | gen = calloc(sizeof(*gen), 1);
| ^
libbpf.c:9209:28: note: earlier argument should specify number of elements, later size of each element

Fix this by inverting the calloc() arguments.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20250717200337.49168-1-technoboy85@gmail.com

authored by

Matteo Croce and committed by
Andrii Nakryiko
0ee30d93 0768e980

+1 -1
+1 -1
tools/lib/bpf/libbpf.c
··· 9210 9210 return libbpf_err(-EFAULT); 9211 9211 if (!OPTS_VALID(opts, gen_loader_opts)) 9212 9212 return libbpf_err(-EINVAL); 9213 - gen = calloc(sizeof(*gen), 1); 9213 + gen = calloc(1, sizeof(*gen)); 9214 9214 if (!gen) 9215 9215 return libbpf_err(-ENOMEM); 9216 9216 gen->opts = opts;