@@ -686,7 +686,6 @@ static int dump_map_elem(int fd, void *key, void *value,
struct bpf_map_info *map_info, struct btf *btf,
json_writer_t *btf_wtr)
{
- int num_elems = 0;
int lookup_errno;
if (!bpf_map_lookup_elem(fd, key, value)) {
@@ -704,9 +703,8 @@ static int dump_map_elem(int fd, void *key, void *value,
} else {
print_entry_plain(map_info, key, value);
}
- num_elems++;
}
- return num_elems;
+ return 0;
}
/* lookup error handling */
@@ -714,7 +712,7 @@ static int dump_map_elem(int fd, void *key, void *value,
if (map_is_map_of_maps(map_info->type) ||
map_is_map_of_progs(map_info->type))
- return 0;
+ return -1;
if (json_output) {
jsonw_start_object(json_wtr);
@@ -738,7 +736,7 @@ static int dump_map_elem(int fd, void *key, void *value,
msg ? : strerror(lookup_errno));
}
- return 0;
+ return -1;
}
static int do_dump(int argc, char **argv)
@@ -800,7 +798,8 @@ static int do_dump(int argc, char **argv)
err = 0;
break;
}
- num_elems += dump_map_elem(fd, key, value, &info, btf, btf_wtr);
+ if (!dump_map_elem(fd, key, value, &info, btf, btf_wtr))
+ num_elems++;
prev_key = key;
}