Commit e28ff1a8 authored by Joe Stringer's avatar Joe Stringer Committed by Arnaldo Carvalho de Melo

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: default avatarJoe Stringer <joe@ovn.org>
Acked-by: default avatarWang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org
Link: http://lkml.kernel.org/r/20170123011128.26534-5-joe@ovn.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7803ba73
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include <linux/err.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/list.h> #include <linux/list.h>
...@@ -1542,3 +1543,10 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset) ...@@ -1542,3 +1543,10 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
} }
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
long libbpf_get_error(const void *ptr)
{
if (IS_ERR(ptr))
return PTR_ERR(ptr);
return 0;
}
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#define __BPF_LIBBPF_H #define __BPF_LIBBPF_H
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <linux/err.h>
#include <sys/types.h> // for size_t #include <sys/types.h> // for size_t
enum libbpf_errno { enum libbpf_errno {
...@@ -234,4 +234,6 @@ int bpf_map__set_priv(struct bpf_map *map, void *priv, ...@@ -234,4 +234,6 @@ int bpf_map__set_priv(struct bpf_map *map, void *priv,
bpf_map_clear_priv_t clear_priv); bpf_map_clear_priv_t clear_priv);
void *bpf_map__priv(struct bpf_map *map); void *bpf_map__priv(struct bpf_map *map);
long libbpf_get_error(const void *ptr);
#endif #endif
...@@ -13,7 +13,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz) ...@@ -13,7 +13,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
struct bpf_object *obj; struct bpf_object *obj;
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL); obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
if (IS_ERR(obj)) if (libbpf_get_error(obj))
return TEST_FAIL; return TEST_FAIL;
bpf_object__close(obj); bpf_object__close(obj);
return TEST_OK; return TEST_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment