Skip to content

Commit edc21dc

Browse files
Yinjun Zhanganakryiko
Yinjun Zhang
authored andcommitted
bpftool: Fix the error when lookup in no-btf maps
When reworking btf__get_from_id() in commit a19f93c the error handling when calling bpf_btf_get_fd_by_id() changed. Before the rework if bpf_btf_get_fd_by_id() failed the error would not be propagated to callers of btf__get_from_id(), after the rework it is. This lead to a change in behavior in print_key_value() that now prints an error when trying to lookup keys in maps with no btf available. Fix this by following the way used in dumping maps to allow to look up keys in no-btf maps, by which it decides whether and where to get the btf info according to the btf value type. Fixes: a19f93c ("libbpf: Add internal helper to load BTF data by FD") Signed-off-by: Yinjun Zhang <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Niklas Söderlund <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9c3de61 commit edc21dc

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

tools/bpf/bpftool/map.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,9 @@ static void print_key_value(struct bpf_map_info *info, void *key,
10541054
json_writer_t *btf_wtr;
10551055
struct btf *btf;
10561056

1057-
btf = btf__load_from_kernel_by_id(info->btf_id);
1058-
if (libbpf_get_error(btf)) {
1059-
p_err("failed to get btf");
1057+
btf = get_map_kv_btf(info);
1058+
if (libbpf_get_error(btf))
10601059
return;
1061-
}
10621060

10631061
if (json_output) {
10641062
print_entry_json(info, key, value, btf);

0 commit comments

Comments
 (0)