Skip to content

Commit 436e4bd

Browse files
argesNobody
authored andcommitted
bpftool: ensure bytes_memlock json output is correct
If a bpf map is created over 2^32 the memlock value as displayed in JSON format will be incorrect. Use atoll instead of atoi so that the correct number is displayed. ``` $ bpftool map create /sys/fs/bpf/test_bpfmap type hash key 4 \ value 1024 entries 4194304 name test_bpfmap $ bpftool map list 1: hash name test_bpfmap flags 0x0 key 4B value 1024B max_entries 4194304 memlock 4328521728B $ sudo bpftool map list -j | jq .[].bytes_memlock 33554432 ``` Signed-off-by: Chris J Arges <[email protected]>
1 parent 1487f29 commit 436e4bd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

tools/bpf/bpftool/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
504504
jsonw_uint_field(json_wtr, "max_entries", info->max_entries);
505505

506506
if (memlock)
507-
jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
507+
jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
508508
free(memlock);
509509

510510
if (info->type == BPF_MAP_TYPE_PROG_ARRAY) {

tools/bpf/bpftool/prog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
485485

486486
memlock = get_fdinfo(fd, "memlock");
487487
if (memlock)
488-
jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
488+
jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
489489
free(memlock);
490490

491491
if (info->nr_map_ids)

0 commit comments

Comments
 (0)