bpf: Refactor ARRAY_SIZE macro to bpf_util.h
authorMartin KaFai Lau <kafai@fb.com>
Wed, 8 Aug 2018 08:01:27 +0000 (01:01 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 10 Aug 2018 23:58:46 +0000 (01:58 +0200)
This patch refactors the ARRAY_SIZE macro to bpf_util.h.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/bpf_util.h
tools/testing/selftests/bpf/test_align.c
tools/testing/selftests/bpf/test_btf.c
tools/testing/selftests/bpf/test_sock.c
tools/testing/selftests/bpf/test_sock_addr.c
tools/testing/selftests/bpf/test_verifier.c

index d0811b3d6a6f165be201ae7a74afe1ad2b7fcfcb..315a44fa32af3353bf6eb90fd3d324121319d319 100644 (file)
@@ -44,4 +44,8 @@ static inline unsigned int bpf_num_possible_cpus(void)
                name[bpf_num_possible_cpus()]
 #define bpf_percpu(name, cpu) name[(cpu)].v
 
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 #endif /* __BPF_UTIL__ */
index 6b1b302310feb6881629ecaab0911c79d6f32efd..5f377ec53f2f8a1df0fecac7a624f43133c4b8f2 100644 (file)
 
 #include "../../../include/linux/filter.h"
 #include "bpf_rlimit.h"
-
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_util.h"
 
 #define MAX_INSNS      512
 #define MAX_MATCHES    16
index 7fa8c800c540066bce7ab5041c485012b40ffbcd..6b5cfeb7a9cc36cca95202b0e4f69ee45bb324c5 100644 (file)
@@ -19,6 +19,7 @@
 #include <bpf/btf.h>
 
 #include "bpf_rlimit.h"
+#include "bpf_util.h"
 
 static uint32_t pass_cnt;
 static uint32_t error_cnt;
@@ -93,10 +94,6 @@ static int __base_pr(const char *format, ...)
 #define MAX_NR_RAW_TYPES 1024
 #define BTF_LOG_BUF_SIZE 65535
 
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 static struct args {
        unsigned int raw_test_num;
        unsigned int file_test_num;
index f4d99fabc56de89ea0a093b59763f98669573f86..b8ebe2f580741a5cb4aae39e604affc313b31ff4 100644 (file)
 
 #include "cgroup_helpers.h"
 #include "bpf_rlimit.h"
-
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_util.h"
 
 #define CG_PATH                "/foo"
 #define MAX_INSNS      512
index 2e45c92d11111784ff0e5d5b520af48ad986d911..aeeb76a54d633e9e443fdecef7160c924efeb806 100644 (file)
 
 #include "cgroup_helpers.h"
 #include "bpf_rlimit.h"
+#include "bpf_util.h"
 
 #ifndef ENOTSUPP
 # define ENOTSUPP 524
 #endif
 
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define CG_PATH        "/foo"
 #define CONNECT4_PROG_PATH     "./connect4_prog.o"
 #define CONNECT6_PROG_PATH     "./connect6_prog.o"
index 452cf5c6c784b99b21a495ecfa3d9386f4fd99bb..67c412d19c0909b01d96175cb215554bc2998a24 100644 (file)
 #endif
 #include "bpf_rlimit.h"
 #include "bpf_rand.h"
+#include "bpf_util.h"
 #include "../../../include/linux/filter.h"
 
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define MAX_INSNS      BPF_MAXINSNS
 #define MAX_FIXUPS     8
 #define MAX_NR_MAPS    8