summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-06-17 15:26:50 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2019-06-17 18:08:54 -0400
commitd7fe74f9404a9736e9d4f754c30e43640a822c17 (patch)
tree6d2addde09dcb0095db479aa801575f173e886b8
parent7f94208c8f9a0a6d2ff0e0c0858c00ad8e5c8617 (diff)
libbpf: add common min/max macro to libbpf_internal.h
Multiple files in libbpf redefine their own definitions for min/max. Let's define them in libbpf_internal.h and use those everywhere. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--tools/lib/bpf/bpf.c7
-rw-r--r--tools/lib/bpf/bpf_prog_linfo.c5
-rw-r--r--tools/lib/bpf/btf.c3
-rw-r--r--tools/lib/bpf/btf_dump.c3
-rw-r--r--tools/lib/bpf/libbpf_internal.h7
5 files changed, 10 insertions, 15 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 0d4b4fe10a84..c7d7993c44bb 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -26,10 +26,11 @@
26#include <memory.h> 26#include <memory.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <asm/unistd.h> 28#include <asm/unistd.h>
29#include <errno.h>
29#include <linux/bpf.h> 30#include <linux/bpf.h>
30#include "bpf.h" 31#include "bpf.h"
31#include "libbpf.h" 32#include "libbpf.h"
32#include <errno.h> 33#include "libbpf_internal.h"
33 34
34/* 35/*
35 * When building perf, unistd.h is overridden. __NR_bpf is 36 * When building perf, unistd.h is overridden. __NR_bpf is
@@ -53,10 +54,6 @@
53# endif 54# endif
54#endif 55#endif
55 56
56#ifndef min
57#define min(x, y) ((x) < (y) ? (x) : (y))
58#endif
59
60static inline __u64 ptr_to_u64(const void *ptr) 57static inline __u64 ptr_to_u64(const void *ptr)
61{ 58{
62 return (__u64) (unsigned long) ptr; 59 return (__u64) (unsigned long) ptr;
diff --git a/tools/lib/bpf/bpf_prog_linfo.c b/tools/lib/bpf/bpf_prog_linfo.c
index 6978314ea7f6..8c67561c93b0 100644
--- a/tools/lib/bpf/bpf_prog_linfo.c
+++ b/tools/lib/bpf/bpf_prog_linfo.c
@@ -6,10 +6,7 @@
6#include <linux/err.h> 6#include <linux/err.h>
7#include <linux/bpf.h> 7#include <linux/bpf.h>
8#include "libbpf.h" 8#include "libbpf.h"
9 9#include "libbpf_internal.h"
10#ifndef min
11#define min(x, y) ((x) < (y) ? (x) : (y))
12#endif
13 10
14struct bpf_prog_linfo { 11struct bpf_prog_linfo {
15 void *raw_linfo; 12 void *raw_linfo;
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index b2478e98c367..467224feb43b 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -16,9 +16,6 @@
16#include "libbpf_internal.h" 16#include "libbpf_internal.h"
17#include "hashmap.h" 17#include "hashmap.h"
18 18
19#define max(a, b) ((a) > (b) ? (a) : (b))
20#define min(a, b) ((a) < (b) ? (a) : (b))
21
22#define BTF_MAX_NR_TYPES 0x7fffffff 19#define BTF_MAX_NR_TYPES 0x7fffffff
23#define BTF_MAX_STR_OFFSET 0x7fffffff 20#define BTF_MAX_STR_OFFSET 0x7fffffff
24 21
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 4b22db77e2cc..7065bb5b2752 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -18,9 +18,6 @@
18#include "libbpf.h" 18#include "libbpf.h"
19#include "libbpf_internal.h" 19#include "libbpf_internal.h"
20 20
21#define min(x, y) ((x) < (y) ? (x) : (y))
22#define max(x, y) ((x) < (y) ? (y) : (x))
23
24static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t"; 21static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
25static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1; 22static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
26 23
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 850f7bdec5cb..554a7856dc2d 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -23,6 +23,13 @@
23#define BTF_PARAM_ENC(name, type) (name), (type) 23#define BTF_PARAM_ENC(name, type) (name), (type)
24#define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size) 24#define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)
25 25
26#ifndef min
27# define min(x, y) ((x) < (y) ? (x) : (y))
28#endif
29#ifndef max
30# define max(x, y) ((x) < (y) ? (y) : (x))
31#endif
32
26extern void libbpf_print(enum libbpf_print_level level, 33extern void libbpf_print(enum libbpf_print_level level,
27 const char *format, ...) 34 const char *format, ...)
28 __attribute__((format(printf, 2, 3))); 35 __attribute__((format(printf, 2, 3)));