return 0;
}
-static void
+static int
bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
{
int i;
Elf_Data *symbols = obj->efile.symbols;
if (!symbols || maps_shndx < 0)
- return;
+ return -EINVAL;
for (i = 0; i < symbols->d_size / sizeof(GElf_Sym); i++) {
GElf_Sym sym;
continue;
}
obj->maps[map_idx].name = strdup(map_name);
+ if (!obj->maps[map_idx].name) {
+ pr_warning("failed to alloc map name\n");
+ return -ENOMEM;
+ }
pr_debug("map %zu is \"%s\"\n", map_idx,
obj->maps[map_idx].name);
}
+ return 0;
}
static int bpf_object__elf_collect(struct bpf_object *obj)
}
if (maps_shndx >= 0)
- bpf_object__init_maps_name(obj, maps_shndx);
+ err = bpf_object__init_maps_name(obj, maps_shndx);
out:
return err;
}
struct bpf_map *pos;
bpf_map__for_each(pos, obj) {
- if (strcmp(pos->name, name) == 0)
+ if (pos->name && !strcmp(pos->name, name))
return pos;
}
return NULL;