Skip to contentSkip to conversation

tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_def()

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 8, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw
Commit-ID:  53897a78ca6d4bd64e8c17d76cfec65d237f9447
Gitweb:     http://git.kernel.org/tip/53897a78ca6d4bd64e8c17d76cfec65d237f9447
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 2 Jun 2016 14:21:06 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 6 Jun 2016 18:18:55 -0300

tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_def()

And for consistency, rename it to bpf_map__def(), leaving "get" for reference counting.

Also make it return a const pointer, as suggested by Wang.

---
 tools/lib/bpf/libbpf.c       |  8 ++-----
 tools/lib/bpf/libbpf.h       |  2 +-
 tools/perf/util/bpf-loader.c | 52 ++++++++++++++++++++------------------------
 3 files changed, 27 insertions(+), 35 deletions(-)
tools/lib/bpf/libbpf.c +2 -6
index 4dc617b..215be67 100644
@@ -1319,13 +1319,9 @@ int bpf_map__get_fd(struct bpf_map *map)
 	return map->fd;
 }
 
-int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef)
+const struct bpf_map_def *bpf_map__def(struct bpf_map *map)
 {
-	if (!map || !pdef)
-		return -EINVAL;
-
-	*pdef = map->def;
-	return 0;
+	return map ? &map->def : ERR_PTR(-EINVAL);
 }
 
 const char *bpf_map__name(struct bpf_map *map)
tools/lib/bpf/libbpf.h +1 -1
index f8fbba4..bad5bac 100644
@@ -181,7 +181,7 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
 	     (pos) = bpf_map__next((pos), (obj)))
 
 int bpf_map__get_fd(struct bpf_map *map);
-int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef);
+const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
 const char *bpf_map__name(struct bpf_map *map);
 
 typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
tools/perf/util/bpf-loader.c +24 -28

164 lines not on this page · raw message