linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libbpf: fix array_size.cocci warning
@ 2022-03-06  2:34 Guo Zhengkui
  2022-03-07  8:04 ` Magnus Karlsson
  2022-03-08  6:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Guo Zhengkui @ 2022-03-06  2:34 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Björn Töpel, Magnus Karlsson, Jonathan Lemon,
	netdev, bpf, linux-kernel
  Cc: Guo Zhengkui

Fix the following coccicheck warning:
tools/lib/bpf/bpf.c:114:31-32: WARNING: Use ARRAY_SIZE
tools/lib/bpf/xsk.c:484:34-35: WARNING: Use ARRAY_SIZE
tools/lib/bpf/xsk.c:485:35-36: WARNING: Use ARRAY_SIZE

It has been tested with gcc (Debian 8.3.0-6) 8.3.0 on x86_64.

Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
 tools/lib/bpf/bpf.c | 3 ++-
 tools/lib/bpf/xsk.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 418b259166f8..3c7c180294fa 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <linux/bpf.h>
 #include <linux/filter.h>
+#include <linux/kernel.h>
 #include <limits.h>
 #include <sys/resource.h>
 #include "bpf.h"
@@ -111,7 +112,7 @@ int probe_memcg_account(void)
 		BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
 		BPF_EXIT_INSN(),
 	};
-	size_t insn_cnt = sizeof(insns) / sizeof(insns[0]);
+	size_t insn_cnt = ARRAY_SIZE(insns);
 	union bpf_attr attr;
 	int prog_fd;
 
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index edafe56664f3..19dbefb1caf1 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
 		BPF_EMIT_CALL(BPF_FUNC_redirect_map),
 		BPF_EXIT_INSN(),
 	};
-	size_t insns_cnt[] = {sizeof(prog) / sizeof(struct bpf_insn),
-			      sizeof(prog_redirect_flags) / sizeof(struct bpf_insn),
+	size_t insns_cnt[] = {ARRAY_SIZE(prog),
+			      ARRAY_SIZE(prog_redirect_flags),
 	};
 	struct bpf_insn *progs[] = {prog, prog_redirect_flags};
 	enum xsk_prog option = get_xsk_prog();
-- 
2.20.1


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

* Re: [PATCH] libbpf: fix array_size.cocci warning
  2022-03-06  2:34 [PATCH] libbpf: fix array_size.cocci warning Guo Zhengkui
@ 2022-03-07  8:04 ` Magnus Karlsson
  2022-03-08  6:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Magnus Karlsson @ 2022-03-07  8:04 UTC (permalink / raw)
  To: Guo Zhengkui
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Björn Töpel, Magnus Karlsson, Jonathan Lemon,
	Network Development, bpf, open list

On Sun, Mar 6, 2022 at 5:20 AM Guo Zhengkui <guozhengkui@vivo.com> wrote:
>
> Fix the following coccicheck warning:
> tools/lib/bpf/bpf.c:114:31-32: WARNING: Use ARRAY_SIZE
> tools/lib/bpf/xsk.c:484:34-35: WARNING: Use ARRAY_SIZE
> tools/lib/bpf/xsk.c:485:35-36: WARNING: Use ARRAY_SIZE

Thanks for the fix. Note that the AF_XDP support has been deprecated
and will be removed in the 1.0 libbpf release. So there is no point in
fixing this for the xsk.c file. These days, the AF_XDP support resides
in libxdp. I checked if your patch would apply to libxdp, but the
loading of the default program is handled differently there, so this
line does not exist anymore.

> It has been tested with gcc (Debian 8.3.0-6) 8.3.0 on x86_64.
>
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
>  tools/lib/bpf/bpf.c | 3 ++-
>  tools/lib/bpf/xsk.c | 4 ++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 418b259166f8..3c7c180294fa 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -29,6 +29,7 @@
>  #include <errno.h>
>  #include <linux/bpf.h>
>  #include <linux/filter.h>
> +#include <linux/kernel.h>
>  #include <limits.h>
>  #include <sys/resource.h>
>  #include "bpf.h"
> @@ -111,7 +112,7 @@ int probe_memcg_account(void)
>                 BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
>                 BPF_EXIT_INSN(),
>         };
> -       size_t insn_cnt = sizeof(insns) / sizeof(insns[0]);
> +       size_t insn_cnt = ARRAY_SIZE(insns);
>         union bpf_attr attr;
>         int prog_fd;
>
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index edafe56664f3..19dbefb1caf1 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
>                 BPF_EMIT_CALL(BPF_FUNC_redirect_map),
>                 BPF_EXIT_INSN(),
>         };
> -       size_t insns_cnt[] = {sizeof(prog) / sizeof(struct bpf_insn),
> -                             sizeof(prog_redirect_flags) / sizeof(struct bpf_insn),
> +       size_t insns_cnt[] = {ARRAY_SIZE(prog),
> +                             ARRAY_SIZE(prog_redirect_flags),
>         };
>         struct bpf_insn *progs[] = {prog, prog_redirect_flags};
>         enum xsk_prog option = get_xsk_prog();
> --
> 2.20.1
>

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

* Re: [PATCH] libbpf: fix array_size.cocci warning
  2022-03-06  2:34 [PATCH] libbpf: fix array_size.cocci warning Guo Zhengkui
  2022-03-07  8:04 ` Magnus Karlsson
@ 2022-03-08  6:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-08  6:20 UTC (permalink / raw)
  To: Guo Zhengkui
  Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh, bjorn, magnus.karlsson, jonathan.lemon, netdev, bpf,
	linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sun,  6 Mar 2022 10:34:26 +0800 you wrote:
> Fix the following coccicheck warning:
> tools/lib/bpf/bpf.c:114:31-32: WARNING: Use ARRAY_SIZE
> tools/lib/bpf/xsk.c:484:34-35: WARNING: Use ARRAY_SIZE
> tools/lib/bpf/xsk.c:485:35-36: WARNING: Use ARRAY_SIZE
> 
> It has been tested with gcc (Debian 8.3.0-6) 8.3.0 on x86_64.
> 
> [...]

Here is the summary with links:
  - libbpf: fix array_size.cocci warning
    https://git.kernel.org/bpf/bpf-next/c/04b6de649e12

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:[~2022-03-08  6:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-06  2:34 [PATCH] libbpf: fix array_size.cocci warning Guo Zhengkui
2022-03-07  8:04 ` Magnus Karlsson
2022-03-08  6:20 ` 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;
as well as URLs for NNTP newsgroup(s).