aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/bpf/libbpf.c8
-rw-r--r--tools/lib/bpf/libbpf.h4
-rw-r--r--tools/perf/tests/llvm.c2
3 files changed, 12 insertions, 2 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 406838fa9c4f..e6cd62b1264b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -28,6 +28,7 @@
28#include <fcntl.h> 28#include <fcntl.h>
29#include <errno.h> 29#include <errno.h>
30#include <asm/unistd.h> 30#include <asm/unistd.h>
31#include <linux/err.h>
31#include <linux/kernel.h> 32#include <linux/kernel.h>
32#include <linux/bpf.h> 33#include <linux/bpf.h>
33#include <linux/list.h> 34#include <linux/list.h>
@@ -1542,3 +1543,10 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
1542 } 1543 }
1543 return ERR_PTR(-ENOENT); 1544 return ERR_PTR(-ENOENT);
1544} 1545}
1546
1547long libbpf_get_error(const void *ptr)
1548{
1549 if (IS_ERR(ptr))
1550 return PTR_ERR(ptr);
1551 return 0;
1552}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 2188ccdc0e2d..4014d1ba5e3d 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -22,8 +22,8 @@
22#define __BPF_LIBBPF_H 22#define __BPF_LIBBPF_H
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <stdint.h>
25#include <stdbool.h> 26#include <stdbool.h>
26#include <linux/err.h>
27#include <sys/types.h> // for size_t 27#include <sys/types.h> // for size_t
28 28
29enum libbpf_errno { 29enum libbpf_errno {
@@ -234,4 +234,6 @@ int bpf_map__set_priv(struct bpf_map *map, void *priv,
234 bpf_map_clear_priv_t clear_priv); 234 bpf_map_clear_priv_t clear_priv);
235void *bpf_map__priv(struct bpf_map *map); 235void *bpf_map__priv(struct bpf_map *map);
236 236
237long libbpf_get_error(const void *ptr);
238
237#endif 239#endif
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 02a33ebcd992..d357dab72e68 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -13,7 +13,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
13 struct bpf_object *obj; 13 struct bpf_object *obj;
14 14
15 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL); 15 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
16 if (IS_ERR(obj)) 16 if (libbpf_get_error(obj))
17 return TEST_FAIL; 17 return TEST_FAIL;
18 bpf_object__close(obj); 18 bpf_object__close(obj);
19 return TEST_OK; 19 return TEST_OK;