[PATCH] libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c

longlong yan posted 1 patch 1 week, 2 days ago
.../selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c    | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c
Posted by longlong yan 1 week, 2 days ago
The ARRAY_SIZE macro is more compact and more formal in linux source.

Fixes: b1487dc1b181 ("selftests/bpf: Add selftests for libarena buddy allocator")
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
 .../selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
index 3266a28f53d7..9c94a5167a50 100644
--- a/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
@@ -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) {
-- 
2.43.0
Re: [PATCH] libarena/selftests: use ARRAY_SIZE macro in st_asan_buddy.bpf.c
Posted by Emil Tsalapatis 1 week, 1 day ago
On Thu Jul 16, 2026 at 3:11 AM EDT, longlong yan wrote:
> The ARRAY_SIZE macro is more compact and more formal in linux source.
>
> Fixes: b1487dc1b181 ("selftests/bpf: Add selftests for libarena buddy allocator")
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
>  .../selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c    | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
> index 3266a28f53d7..9c94a5167a50 100644
> --- a/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
> +++ b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
> @@ -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) {

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