[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-e28ff1a8382ee02b10cf11cf3b48541dc3d14a58@git.kernel.org>
Date: Thu, 26 Jan 2017 07:31:12 -0800
From: tip-bot for Joe Stringer <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: ast@...com, hpa@...or.com, tglx@...utronix.de, mingo@...nel.org,
acme@...hat.com, wangnan0@...wei.com, joe@....org,
linux-kernel@...r.kernel.org, daniel@...earbox.net
Subject: [tip:perf/core] tools lib bpf: Add libbpf_get_error()
Commit-ID: e28ff1a8382ee02b10cf11cf3b48541dc3d14a58
Gitweb: http://git.kernel.org/tip/e28ff1a8382ee02b10cf11cf3b48541dc3d14a58
Author: Joe Stringer <joe@....org>
AuthorDate: Sun, 22 Jan 2017 17:11:25 -0800
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Thu, 26 Jan 2017 11:42:58 -0300
tools lib bpf: Add libbpf_get_error()
This function will turn a libbpf pointer into a standard error code (or
0 if the pointer is valid).
This also allows removal of the dependency on linux/err.h in the public
header file, which causes problems in userspace programs built against
libbpf.
Signed-off-by: Joe Stringer <joe@....org>
Acked-by: Wang Nan <wangnan0@...wei.com>
Cc: Alexei Starovoitov <ast@...com>
Cc: Daniel Borkmann <daniel@...earbox.net>
Cc: netdev@...r.kernel.org
Link: http://lkml.kernel.org/r/20170123011128.26534-5-joe@ovn.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/lib/bpf/libbpf.c | 8 ++++++++
tools/lib/bpf/libbpf.h | 4 +++-
tools/perf/tests/llvm.c | 2 +-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 406838f..e6cd62b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <errno.h>
#include <asm/unistd.h>
+#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/bpf.h>
#include <linux/list.h>
@@ -1542,3 +1543,10 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
}
return ERR_PTR(-ENOENT);
}
+
+long libbpf_get_error(const void *ptr)
+{
+ if (IS_ERR(ptr))
+ return PTR_ERR(ptr);
+ return 0;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 2188ccd..4014d1b 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -22,8 +22,8 @@
#define __BPF_LIBBPF_H
#include <stdio.h>
+#include <stdint.h>
#include <stdbool.h>
-#include <linux/err.h>
#include <sys/types.h> // for size_t
enum libbpf_errno {
@@ -234,4 +234,6 @@ int bpf_map__set_priv(struct bpf_map *map, void *priv,
bpf_map_clear_priv_t clear_priv);
void *bpf_map__priv(struct bpf_map *map);
+long libbpf_get_error(const void *ptr);
+
#endif
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 02a33eb..d357dab 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)
struct bpf_object *obj;
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
- if (IS_ERR(obj))
+ if (libbpf_get_error(obj))
return TEST_FAIL;
bpf_object__close(obj);
return TEST_OK;
Powered by blists - more mailing lists