Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Fix kmem_cache iterator draining

The closing parentheses around the read syscall is misplaced, causing
single byte reads from the iterator instead of buf sized reads. While
the end result is the same, many more read calls than necessary are
performed.

$ tools/testing/selftests/bpf/vmtest.sh "./test_progs -t kmem_cache_iter"
145/1 kmem_cache_iter/check_task_struct:OK
145/2 kmem_cache_iter/check_slabinfo:OK
145/3 kmem_cache_iter/open_coded_iter:OK
145 kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED

Fixes: a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
Signed-off-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://patch.msgid.link/20250428180256.1482899-1-tjmercier@google.com

authored by

T.J. Mercier and committed by
Martin KaFai Lau
38d976c3 8e64c387

+1 -1
+1 -1
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c
··· 104 104 goto destroy; 105 105 106 106 memset(buf, 0, sizeof(buf)); 107 - while (read(iter_fd, buf, sizeof(buf) > 0)) { 107 + while (read(iter_fd, buf, sizeof(buf)) > 0) { 108 108 /* Read out all contents */ 109 109 printf("%s", buf); 110 110 }