]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
libbpf: Fix warning in calloc() usage
authorMatteo Croce <teknoraver@meta.com>
Thu, 17 Jul 2025 20:03:37 +0000 (22:03 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 18 Jul 2025 15:29:50 +0000 (08:29 -0700)
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
tools/lib/bpf/libbpf.c

index aee36402f0a31d56acfecf34f4ab1ccc6c4646f4..af85989ae2c99b21103790945db2882c50292998 100644 (file)
@@ -9210,7 +9210,7 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
                return libbpf_err(-EFAULT);
        if (!OPTS_VALID(opts, gen_loader_opts))
                return libbpf_err(-EINVAL);
-       gen = calloc(sizeof(*gen), 1);
+       gen = calloc(1, sizeof(*gen));
        if (!gen)
                return libbpf_err(-ENOMEM);
        gen->opts = opts;