Commit 04b6de64 authored by Guo Zhengkui's avatar Guo Zhengkui Committed by Andrii Nakryiko

libbpf: Fix array_size.cocci warning

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: default avatarGuo Zhengkui <guozhengkui@vivo.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220306023426.19324-1-guozhengkui@vivo.com
parent 03b9c7fa
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <errno.h> #include <errno.h>
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/filter.h> #include <linux/filter.h>
#include <linux/kernel.h>
#include <limits.h> #include <limits.h>
#include <sys/resource.h> #include <sys/resource.h>
#include "bpf.h" #include "bpf.h"
...@@ -111,7 +112,7 @@ int probe_memcg_account(void) ...@@ -111,7 +112,7 @@ int probe_memcg_account(void)
BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns), BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}; };
size_t insn_cnt = sizeof(insns) / sizeof(insns[0]); size_t insn_cnt = ARRAY_SIZE(insns);
union bpf_attr attr; union bpf_attr attr;
int prog_fd; int prog_fd;
......
...@@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk) ...@@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
BPF_EMIT_CALL(BPF_FUNC_redirect_map), BPF_EMIT_CALL(BPF_FUNC_redirect_map),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}; };
size_t insns_cnt[] = {sizeof(prog) / sizeof(struct bpf_insn), size_t insns_cnt[] = {ARRAY_SIZE(prog),
sizeof(prog_redirect_flags) / sizeof(struct bpf_insn), ARRAY_SIZE(prog_redirect_flags),
}; };
struct bpf_insn *progs[] = {prog, prog_redirect_flags}; struct bpf_insn *progs[] = {prog, prog_redirect_flags};
enum xsk_prog option = get_xsk_prog(); enum xsk_prog option = get_xsk_prog();
......
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