libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c
Subsystems (3)
PATCH 1/1 libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c
The ARRAY_SIZE macro is more compact and more formal in linux source.
--- .../selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c +2 -2
@@ -163,7 +163,7 @@ __weak int asan_test_buddy_oob(void)return ret; } -for (i = zero; i <sizeof (sizes) /sizeof (sizes[0 ]) && can_loop; i++) { +for (i = zero; i <ARRAY_SIZE (sizes) && can_loop; i++) {barrier_var (i); ret =asan_test_buddy_oob_single (sizes[i]);if (ret) {
@@ -201,7 +201,7 @@ __weak int asan_test_buddy_uaf(void)return ret; } -for (i = zero; i <sizeof (sizes) /sizeof (sizes[0 ]) && can_loop; i++) { +for (i = zero; i <ARRAY_SIZE (sizes) && can_loop; i++) {barrier_var (i); ret =asan_test_buddy_uaf_single (sizes[i]);if (ret) {
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The commit introduces the `ARRAY_SIZE` macro into a BPF program without defining or including it…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit introduces the ARRAY_SIZE macro into a BPF program without defining or including it, causing a compilation failure. --
--- Patch [1]: [PATCH] libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c --- commit 70521e8b40248839f7100def222aa4fb06724c32
Author: longlong yan <[email protected]>
libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c
This commit replaces manual array size calculations with the ARRAY_SIZE macro in the asan_test_buddy_oob and asan_test_buddy_uaf functions to make the code more compact.
tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c __weak int asan_test_buddy_oob(void) · line 166
Quoted 10 lines
tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c +1
-1@@ -163,7 +163,7 @@ __weak int asan_test_buddy_oob(void)return ret; } -for (i = zero; i <sizeof (sizes) /sizeof (sizes[0 ]) && can_loop; i++) { +for (i = zero; i <ARRAY_SIZE (sizes) && can_loop; i++) {
[Severity: Low]
Does this cause a compilation failure when building the BPF selftests?
It appears that ARRAY_SIZE is not defined in this BPF program or its currently included headers. Would we need to define ARRAY_SIZE locally in this file, or include a header that provides it specifically for BPF environments?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Emil Tsalapatis
reviewerQuoted 22 lines · longlong yan
The
ARRAY_SIZEmacro is more compact and more formal in linux source.Fixes b1487dc1b181 ("selftests/bpf: Add selftests for libarena buddy allocator")Signed-off-by longlong yan <[email protected]>--- .../selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c +1
-1@@ -163,7 +163,7 @@ __weak int asan_test_buddy_oob(void)return ret; } -for (i = zero; i <sizeof (sizes) /sizeof (sizes[0 ]) && can_loop; i++) { +for (i = zero; i <ARRAY_SIZE (sizes) && can_loop; i++) {barrier_var (i); ret =asan_test_buddy_oob_single (sizes[i]);if (ret) {
tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c __weak int asan_test_buddy_uaf(void) · line 207
Quoted 8 lines
tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c +1
-1@@ -201,7 +201,7 @@ __weak int asan_test_buddy_uaf(void)return ret; } -for (i = zero; i <sizeof (sizes) /sizeof (sizes[0 ]) && can_loop; i++) { +for (i = zero; i <ARRAY_SIZE (sizes) && can_loop; i++) {barrier_var (i); ret =asan_test_buddy_uaf_single (sizes[i]);if (ret) {
As the bot says, this doesn't compile. The sizeof(array) / sizeof(array[0]) is only present in libarena for selftests, so I it's not worth bringing in the macro or adding extra headers even if it makes the code nicer.
pw-bot: cr