@@ -1253,21 +1253,22 @@ __bpf_map__config_event(struct bpf_map *map,
struct parse_events_term *term,
struct evlist *evlist)
{
- struct bpf_map_op *op;
const char *map_name = bpf_map__name(map);
- struct evsel *evsel = evlist__find_evsel_by_str(evlist, term->val.str);
+ struct bpf_map_op *op;
+ struct evsel *evsel;
+ if (!map) {
+ pr_debug("Map '%s' is invalid\n", map_name);
+ return -BPF_LOADER_ERRNO__INTERNAL;
+ }
+
+ evsel = evlist__find_evsel_by_str(evlist, term->val.str);
if (!evsel) {
pr_debug("Event (for '%s') '%s' doesn't exist\n",
map_name, term->val.str);
return -BPF_LOADER_ERRNO__OBJCONF_MAP_NOEVT;
}
- if (!map) {
- pr_debug("Map '%s' is invalid\n", map_name);
- return PTR_ERR(map);
- }
-
/*
* No need to check key_size and value_size:
* kernel has already checked them.
@@ -36,7 +36,7 @@ int bpf_map__fprintf(struct bpf_map *map, FILE *fp)
return fd;
if (!map)
- return PTR_ERR(map);
+ return -EINVAL;
err = -ENOMEM;
key = malloc(bpf_map__key_size(map));
Passing NULL to PTR_ERR will result in 0 (success), also move evlist__find_evsel_by_str() behind for minor optimization. Fixes: 924b1cd61148 ("perf: Stop using bpf_map__def() API") Signed-off-by: YueHaibing <yuehaibing@huawei.com> --- tools/perf/util/bpf-loader.c | 15 ++++++++------- tools/perf/util/bpf_map.c | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-)