]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: Move ARRAY_SIZE to bpf_misc.h
authorJiri Olsa <jolsa@kernel.org>
Wed, 26 Jun 2024 13:47:19 +0000 (15:47 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 27 Jun 2024 00:08:43 +0000 (17:08 -0700)
ARRAY_SIZE is used on multiple places, move its definition in
bpf_misc.h header.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Link: https://lore.kernel.org/bpf/20240626134719.3893748-1-jolsa@kernel.org
14 files changed:
tools/testing/selftests/bpf/progs/bpf_misc.h
tools/testing/selftests/bpf/progs/iters.c
tools/testing/selftests/bpf/progs/kprobe_multi_session.c
tools/testing/selftests/bpf/progs/linked_list.c
tools/testing/selftests/bpf/progs/netif_receive_skb.c
tools/testing/selftests/bpf/progs/profiler.inc.h
tools/testing/selftests/bpf/progs/setget_sockopt.c
tools/testing/selftests/bpf/progs/test_bpf_ma.c
tools/testing/selftests/bpf/progs/test_sysctl_loop1.c
tools/testing/selftests/bpf/progs/test_sysctl_loop2.c
tools/testing/selftests/bpf/progs/test_sysctl_prog.c
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.h
tools/testing/selftests/bpf/progs/verifier_subprog_precision.c

index c0280bd2f340d75fc2e6732c4732a2ee69fdbf73..81097a3f15eb56cfaaf8c2c086257b3ba9f42f50 100644 (file)
 /* make it look to compiler like value is read and written */
 #define __sink(expr) asm volatile("" : "+g"(expr))
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 #endif
index fe65e0952a1e0b70a61a9e22f8d53f0301ffe78f..16bdc3e255913cb9c1f5c0c9c2ef7d38ccab6d39 100644 (file)
@@ -7,8 +7,6 @@
 #include "bpf_misc.h"
 #include "bpf_compiler.h"
 
-#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof((x)[0]))
-
 static volatile int zero = 0;
 
 int my_pid;
index bbba9eb46551157af356bda9f888f1c4aa0fccdc..bd8b7fb7061edd5a6c961e0cbd371e148d6991c7 100644 (file)
@@ -4,8 +4,7 @@
 #include <bpf/bpf_tracing.h>
 #include <stdbool.h>
 #include "bpf_kfuncs.h"
-
-#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof((x)[0]))
+#include "bpf_misc.h"
 
 char _license[] SEC("license") = "GPL";
 
index f69bf3e30321a0fde68506b6f9729b258a373d3a..421f40835acd75927b1e11e6d46ae37139cfa64b 100644 (file)
@@ -4,10 +4,7 @@
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_core_read.h>
 #include "bpf_experimental.h"
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_misc.h"
 
 #include "linked_list.h"
 
index c0062645fc68bbb13f064390f2eccdf4faf233c0..9e067dcbf6075af21a0b1f982708465e5ccde501 100644 (file)
@@ -5,6 +5,7 @@
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_misc.h"
 
 #include <errno.h>
 
@@ -23,10 +24,6 @@ bool skip = false;
 #define BADPTR                 0
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))
-#endif
-
 struct {
        __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
        __uint(max_entries, 1);
index 6957d9f2805eb3009fe972d04e137ab157b05c94..8bd1ebd7d6afdf2942f367c07ab0c4ee2d7410ee 100644 (file)
@@ -9,6 +9,7 @@
 #include "err.h"
 #include "bpf_experimental.h"
 #include "bpf_compiler.h"
+#include "bpf_misc.h"
 
 #ifndef NULL
 #define NULL 0
@@ -133,10 +134,6 @@ struct {
        __uint(max_entries, 16);
 } disallowed_exec_inodes SEC(".maps");
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (int)(sizeof(arr) / sizeof(arr[0]))
-#endif
-
 static INLINE bool IS_ERR(const void* ptr)
 {
        return IS_ERR_VALUE((unsigned long)ptr);
index 7a438600ae986f0027a48a8b10043e567af65437..60518aed1ffcec80be6972860e27dc7c8d1297be 100644 (file)
@@ -6,10 +6,7 @@
 #include <bpf/bpf_core_read.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_misc.h"
 
 extern unsigned long CONFIG_HZ __kconfig;
 
index 3494ca30fa7fe7ecd6c0b7c78b66eb72ff0425cd..4a4e0b8d9b7265c21da366aee5aff867383679e1 100644 (file)
@@ -7,10 +7,6 @@
 #include "bpf_experimental.h"
 #include "bpf_misc.h"
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 struct generic_map_value {
        void *data;
 };
index 7f74077d6622f2fa77666a62ad5bdf4fbe28df4b..548660e299a5a41af7fb2f87cd876b43314231f3 100644 (file)
 #include <bpf/bpf_helpers.h>
 
 #include "bpf_compiler.h"
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_misc.h"
 
 /* tcp_mem sysctl has only 3 ints, but this test is doing TCP_MEM_LOOPS */
 #define TCP_MEM_LOOPS 28  /* because 30 doesn't fit into 512 bytes of stack */
index 68a75436e8af0bf0e3ec6a47d703c2065b980eda..81249d119a8bb267ad5cfb227ee907f8c7085256 100644 (file)
 #include <bpf/bpf_helpers.h>
 
 #include "bpf_compiler.h"
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
+#include "bpf_misc.h"
 
 /* tcp_mem sysctl has only 3 ints, but this test is doing TCP_MEM_LOOPS */
 #define TCP_MEM_LOOPS 20  /* because 30 doesn't fit into 512 bytes of stack */
index efc3c61f78521067555b50d75630466b52cc5efb..bbdd087647899e26c09b518ace5d734eb430445e 100644 (file)
@@ -10,6 +10,7 @@
 #include <bpf/bpf_helpers.h>
 
 #include "bpf_compiler.h"
+#include "bpf_misc.h"
 
 /* Max supported length of a string with unsigned long in base 10 (pow2 - 1). */
 #define MAX_ULONG_STR_LEN 0xF
 /* Max supported length of sysctl value string (pow2). */
 #define MAX_VALUE_STR_LEN 0x40
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 const char tcp_mem_name[] = "net/ipv4/tcp_mem";
 static __always_inline int is_tcp_mem(struct bpf_sysctl *ctx)
 {
index c8e4553648bf4f5d46f0035f86c3d5b7b0ba1b1e..44ee0d037f955cefdc66266afbb8742d94e57387 100644 (file)
@@ -9,6 +9,7 @@
 #include "bpf_kfuncs.h"
 #include "test_siphash.h"
 #include "test_tcp_custom_syncookie.h"
+#include "bpf_misc.h"
 
 #define MAX_PACKET_OFF 0xffff
 
index 29a6a53cf2294bdbdd0a560874cd871ebe9ba4ff..f8b1b7e68d2edc44b297173b9a9b19f0808e91c1 100644 (file)
@@ -7,8 +7,6 @@
 #define __packed __attribute__((__packed__))
 #define __force
 
-#define ARRAY_SIZE(arr)        (sizeof(arr) / sizeof((arr)[0]))
-
 #define swap(a, b)                             \
        do {                                    \
                typeof(a) __tmp = (a);          \
index 4a58e0398e72abf96df7b9a9309b5ad22f2eaa18..6a6fad625f7eecc7f7d3b9778a8e49caadf7d15f 100644 (file)
@@ -8,8 +8,6 @@
 #include "bpf_misc.h"
 #include <../../../tools/include/linux/filter.h>
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-
 int vals[] SEC(".data.vals") = {1, 2, 3, 4};
 
 __naked __noinline __used