Skip to content

Commit

Permalink
libbpf: add common min/max macro to libbpf_internal.h
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andrii Nakryiko authored and Daniel Borkmann committed Jun 17, 2019
1 parent 7f94208 commit d7fe74f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
7 changes: 2 additions & 5 deletions tools/lib/bpf/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#include <memory.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <errno.h>
#include <linux/bpf.h>
#include "bpf.h"
#include "libbpf.h"
#include <errno.h>
#include "libbpf_internal.h"

/*
* When building perf, unistd.h is overridden. __NR_bpf is
Expand All @@ -53,10 +54,6 @@
# endif
#endif

#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif

static inline __u64 ptr_to_u64(const void *ptr)
{
return (__u64) (unsigned long) ptr;
Expand Down
5 changes: 1 addition & 4 deletions tools/lib/bpf/bpf_prog_linfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
#include <linux/err.h>
#include <linux/bpf.h>
#include "libbpf.h"

#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#include "libbpf_internal.h"

struct bpf_prog_linfo {
void *raw_linfo;
Expand Down
3 changes: 0 additions & 3 deletions tools/lib/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "libbpf_internal.h"
#include "hashmap.h"

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define BTF_MAX_NR_TYPES 0x7fffffff
#define BTF_MAX_STR_OFFSET 0x7fffffff

Expand Down
3 changes: 0 additions & 3 deletions tools/lib/bpf/btf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "libbpf.h"
#include "libbpf_internal.h"

#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) < (y) ? (y) : (x))

static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;

Expand Down
7 changes: 7 additions & 0 deletions tools/lib/bpf/libbpf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#define BTF_PARAM_ENC(name, type) (name), (type)
#define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)

#ifndef min
# define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
# define max(x, y) ((x) < (y) ? (y) : (x))
#endif

extern void libbpf_print(enum libbpf_print_level level,
const char *format, ...)
__attribute__((format(printf, 2, 3)));
Expand Down

0 comments on commit d7fe74f

Please sign in to comment.