diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2022-05-10 11:51:59 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2022-05-11 14:06:29 +0200 |
commit | 5eefe17c7ae41bac4d2d281669e8357a10f4d5a4 (patch) | |
tree | 776c3ef83ae05684faf8d6c1d50355f0a96bf4a2 /tools/lib/bpf/libbpf.c | |
parent | 93dafa92e1cf922bd06fa738bc4f85fdfb63a39f (diff) | |
download | linux-5eefe17c7ae41bac4d2d281669e8357a10f4d5a4.tar.bz2 |
libbpf: Clean up ringbuf size adjustment implementation
Drop unused iteration variable, move overflow prevention check into the
for loop.
Fixes: 0087a681fa8c ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220510185159.754299-1-andrii@kernel.org
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index a5904c0ac794..0e74fae25896 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4951,7 +4951,7 @@ static bool is_pow_of_2(size_t x) static size_t adjust_ringbuf_sz(size_t sz) { __u32 page_sz = sysconf(_SC_PAGE_SIZE); - __u32 i, mul; + __u32 mul; /* if user forgot to set any size, make sure they see error */ if (sz == 0) @@ -4967,9 +4967,7 @@ static size_t adjust_ringbuf_sz(size_t sz) * user-set size to satisfy both user size request and kernel * requirements and substitute correct max_entries for map creation. */ - for (i = 0, mul = 1; ; i++, mul <<= 1) { - if (mul > UINT_MAX / page_sz) /* prevent __u32 overflow */ - break; + for (mul = 1; mul <= UINT_MAX / page_sz; mul <<= 1) { if (mul * page_sz > sz) return mul * page_sz; } |