@@ -27,6 +27,10 @@ struct args {
BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \
BTF_INT_ENC(encoding, bits_offset, bits)
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+#endif
+
static int btf_load(void)
{
struct btf_blob {
@@ -82,7 +86,7 @@ int bpf_prog(struct args *ctx)
static __u64 value = 34;
static union bpf_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
- .insn_cnt = sizeof(insns) / sizeof(insns[0]),
+ .insn_cnt = ARRAY_SIZE(insns),
};
int ret;
@@ -21,6 +21,10 @@ struct {
unsigned sum;
} res = {};
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+#endif
+
SEC("raw_tracepoint/sys_enter:skip_loop")
int skip_loop(struct pt_regs *ctx)
{
@@ -64,7 +68,7 @@ int full_loop(struct pt_regs *ctx)
{
/* prevent compiler to optimize everything out */
unsigned * volatile p = (void *)&rdonly_values.a;
- int i = sizeof(rdonly_values.a) / sizeof(rdonly_values.a[0]);
+ int i = ARRAY_SIZE(rdonly_values.a);
unsigned iters = 0, sum = 0;
/* validate verifier can allow full loop as well */
fixes coccinelle warnings due to manual calculation of array size. Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> --- tools/testing/selftests/bpf/progs/syscall.c | 6 +++++- tools/testing/selftests/bpf/progs/test_rdonly_maps.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)