Skip to content

Commit 04b6de6

Browse files
Guo Zhengkuianakryiko
Guo Zhengkui
authored andcommitted
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: Guo Zhengkui <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 03b9c7f commit 04b6de6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

tools/lib/bpf/bpf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <errno.h>
3030
#include <linux/bpf.h>
3131
#include <linux/filter.h>
32+
#include <linux/kernel.h>
3233
#include <limits.h>
3334
#include <sys/resource.h>
3435
#include "bpf.h"
@@ -111,7 +112,7 @@ int probe_memcg_account(void)
111112
BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
112113
BPF_EXIT_INSN(),
113114
};
114-
size_t insn_cnt = sizeof(insns) / sizeof(insns[0]);
115+
size_t insn_cnt = ARRAY_SIZE(insns);
115116
union bpf_attr attr;
116117
int prog_fd;
117118

tools/lib/bpf/xsk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
481481
BPF_EMIT_CALL(BPF_FUNC_redirect_map),
482482
BPF_EXIT_INSN(),
483483
};
484-
size_t insns_cnt[] = {sizeof(prog) / sizeof(struct bpf_insn),
485-
sizeof(prog_redirect_flags) / sizeof(struct bpf_insn),
484+
size_t insns_cnt[] = {ARRAY_SIZE(prog),
485+
ARRAY_SIZE(prog_redirect_flags),
486486
};
487487
struct bpf_insn *progs[] = {prog, prog_redirect_flags};
488488
enum xsk_prog option = get_xsk_prog();

0 commit comments

Comments
 (0)