Skip to content

Commit aa5f0c9

Browse files
iamkafaiborkmann
authored andcommitted
bpf: Refactor ARRAY_SIZE macro to bpf_util.h
This patch refactors the ARRAY_SIZE macro to bpf_util.h. Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 8217ca6 commit aa5f0c9

File tree

6 files changed

+9
-20
lines changed

6 files changed

+9
-20
lines changed

tools/testing/selftests/bpf/bpf_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ static inline unsigned int bpf_num_possible_cpus(void)
4444
name[bpf_num_possible_cpus()]
4545
#define bpf_percpu(name, cpu) name[(cpu)].v
4646

47+
#ifndef ARRAY_SIZE
48+
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49+
#endif
50+
4751
#endif /* __BPF_UTIL__ */

tools/testing/selftests/bpf/test_align.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
#include "../../../include/linux/filter.h"
2020
#include "bpf_rlimit.h"
21-
22-
#ifndef ARRAY_SIZE
23-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
24-
#endif
21+
#include "bpf_util.h"
2522

2623
#define MAX_INSNS 512
2724
#define MAX_MATCHES 16

tools/testing/selftests/bpf/test_btf.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <bpf/btf.h>
2020

2121
#include "bpf_rlimit.h"
22+
#include "bpf_util.h"
2223

2324
static uint32_t pass_cnt;
2425
static uint32_t error_cnt;
@@ -93,10 +94,6 @@ static int __base_pr(const char *format, ...)
9394
#define MAX_NR_RAW_TYPES 1024
9495
#define BTF_LOG_BUF_SIZE 65535
9596

96-
#ifndef ARRAY_SIZE
97-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
98-
#endif
99-
10097
static struct args {
10198
unsigned int raw_test_num;
10299
unsigned int file_test_num;

tools/testing/selftests/bpf/test_sock.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
#include "cgroup_helpers.h"
1616
#include "bpf_rlimit.h"
17-
18-
#ifndef ARRAY_SIZE
19-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
20-
#endif
17+
#include "bpf_util.h"
2118

2219
#define CG_PATH "/foo"
2320
#define MAX_INSNS 512

tools/testing/selftests/bpf/test_sock_addr.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020

2121
#include "cgroup_helpers.h"
2222
#include "bpf_rlimit.h"
23+
#include "bpf_util.h"
2324

2425
#ifndef ENOTSUPP
2526
# define ENOTSUPP 524
2627
#endif
2728

28-
#ifndef ARRAY_SIZE
29-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30-
#endif
31-
3229
#define CG_PATH "/foo"
3330
#define CONNECT4_PROG_PATH "./connect4_prog.o"
3431
#define CONNECT6_PROG_PATH "./connect6_prog.o"

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@
4242
#endif
4343
#include "bpf_rlimit.h"
4444
#include "bpf_rand.h"
45+
#include "bpf_util.h"
4546
#include "../../../include/linux/filter.h"
4647

47-
#ifndef ARRAY_SIZE
48-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49-
#endif
50-
5148
#define MAX_INSNS BPF_MAXINSNS
5249
#define MAX_FIXUPS 8
5350
#define MAX_NR_MAPS 8

0 commit comments

Comments
 (0)