BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1] bpftool: Silence build warning about calloc()
@ 2024-01-16  6:19 Tiezhu Yang
  2024-01-16 11:15 ` Quentin Monnet
  2024-01-16 15:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Tiezhu Yang @ 2024-01-16  6:19 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Quentin Monnet
  Cc: bpf, linux-kernel

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: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/bpf/bpftool/prog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index feb8e305804f..9cb42a3366c0 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -2298,7 +2298,7 @@ static int profile_open_perf_events(struct profiler_bpf *obj)
 	int map_fd;
 
 	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) {
 		p_err("failed to allocate memory for perf_event array: %s",
 		      strerror(errno));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v1] bpftool: Silence build warning about calloc()
  2024-01-16  6:19 [PATCH bpf-next v1] bpftool: Silence build warning about calloc() Tiezhu Yang
@ 2024-01-16 11:15 ` Quentin Monnet
  2024-01-16 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Quentin Monnet @ 2024-01-16 11:15 UTC (permalink / raw)
  To: Tiezhu Yang, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, linux-kernel

2024-01-16 06:19 UTC+0000 ~ Tiezhu Yang <yangtiezhu@loongson.cn>
> 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: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command")
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Thank you!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v1] bpftool: Silence build warning about calloc()
  2024-01-16  6:19 [PATCH bpf-next v1] bpftool: Silence build warning about calloc() Tiezhu Yang
  2024-01-16 11:15 ` Quentin Monnet
@ 2024-01-16 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-16 15:30 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: ast, daniel, andrii, quentin, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 16 Jan 2024 14:19:20 +0800 you wrote:
> 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
> 
> [...]

Here is the summary with links:
  - [bpf-next,v1] bpftool: Silence build warning about calloc()
    https://git.kernel.org/bpf/bpf-next/c/d2729bb2c7e1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-16 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16  6:19 [PATCH bpf-next v1] bpftool: Silence build warning about calloc() Tiezhu Yang
2024-01-16 11:15 ` Quentin Monnet
2024-01-16 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox