[PATCH bpf-next v2] selftests/bpf: Use unsigned loop counter in test_buddy_alloc_free

From: George Guo

Date: Mon Nov 30 2026 - 22:45:29 EST


From: George Guo <guodongtai@xxxxxxxxxx>

test_buddy_alloc_free() picks an allocation size with
alloc_free_sizes[(i * 5) % 8], where i is a signed int. That is a
signed remainder, and building the BPF selftests with clang 19 fails:

test_buddy.bpf.c:109:54: error: unsupported signed division, please convert to unsigned div/mod.

i only counts up from zero, so make it a u32, like the loop counter in
test_buddy_alloc_multiple() and the u32 zero it starts from. The
remainder becomes unsigned and the selected sizes are unchanged.

Fixes: b1487dc1b181 ("selftests/bpf: Add selftests for libarena buddy allocator")
Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
---
v1 was patch 1/5 of "selftests/bpf: Enable private stack, large stack
and arena tests for LoongArch":
https://lore.kernel.org/bpf/20261126055355.9967-2-dongtai.guo@xxxxxxxxx/

Changes in v2:
- Send it on its own. The fix does not depend on LoongArch, while the
rest of that series waits for the LoongArch JIT changes.
- Fix the line number in the quoted error (109, not 80).
- Reword the commit message.

.../testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
index 886a09019566..00f1efe931af 100644
--- a/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
@@ -99,7 +99,8 @@ __weak int test_buddy_alloc_free(void)
{
const int iters = 800;
void __arena *mem;
- int ret, i;
+ int ret;
+ u32 i;

ret = buddy_init(&buddy);
if (ret)

base-commit: 0dbb0bea76960c41194677d39da65cdfd9f813ad
--
2.53.0