Skip to content

Commit

Permalink
bpf: Refactor ARRAY_SIZE macro to bpf_util.h
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin KaFai Lau authored and Daniel Borkmann committed Aug 10, 2018
1 parent 8217ca6 commit aa5f0c9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
4 changes: 4 additions & 0 deletions tools/testing/selftests/bpf/bpf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/test_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

#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
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/test_btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/test_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#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
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/test_sock_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@

#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"
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/test_verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@
#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
Expand Down

0 comments on commit aa5f0c9

Please sign in to comment.