Commit 5eefe17c authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

libbpf: Clean up ringbuf size adjustment implementation

Drop unused iteration variable, move overflow prevention check into the
for loop.

Fixes: 0087a681 ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220510185159.754299-1-andrii@kernel.org
parent 93dafa92
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment