Merge branch 'selftests-bpf-fix-compilation-with-release-1'

Viktor Malik says:

====================
selftests/bpf: Fix compilation with RELEASE=1

When compiling BPF selftests with RELEASE=1 (which most notably adds
-O2), GCC reports several warnings. These are by default treated as
errors and abort the compilation.

This series fixes all of the issues such that selftests can be compiled
with RELEASE=1.
====================

Link: https://patch.msgid.link/cover.1784112948.git.vmalik@redhat.com
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
Kumar Kartikeya Dwivedi 2026-07-20 21:00:58 +02:00
commit 0bcca2a42c
No known key found for this signature in database
GPG Key ID: 472D377B63542F83
4 changed files with 10 additions and 6 deletions

View File

@ -115,7 +115,7 @@ static inline int libarena_asan_init(int arena_asan_init_fd,
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct asan_init_args args;
u64 globals_pages;
u64 globals_pages = 0;
int ret;
ret = libarena_get_globals_pages(arena_asan_init_fd,

View File

@ -23,6 +23,7 @@ static void global_map_resize_bss_subtest(void)
struct bpf_map *map;
const __u32 desired_sz = sizeof(skel->bss->sum) + sysconf(_SC_PAGE_SIZE) * 2;
size_t array_len, actual_sz, new_sz;
int *array;
skel = test_global_map_resize__open();
if (!ASSERT_OK_PTR(skel, "test_global_map_resize__open"))
@ -58,10 +59,13 @@ static void global_map_resize_bss_subtest(void)
goto teardown;
/* fill the newly resized array with ones,
* skipping the first element which was previously set
* skipping the first element which was previously set;
* access through a plain pointer to avoid -Warray-bounds
* since the array was resized beyond its declared length.
*/
array = skel->bss->array;
for (int i = 1; i < array_len; i++)
skel->bss->array[i] = 1;
array[i] = 1;
/* set global const values before loading */
skel->rodata->pid = getpid();

View File

@ -25,10 +25,10 @@ void test_sha256(void)
size_t i;
data = malloc(MAX_LEN);
if (!ASSERT_OK_PTR(data, "malloc"))
if (!ASSERT_NEQ(data, NULL, "malloc"))
goto out;
digests = malloc((MAX_LEN + 1) * SHA256_DIGEST_LENGTH);
if (!ASSERT_OK_PTR(digests, "malloc"))
if (!ASSERT_NEQ(digests, NULL, "malloc"))
goto out;
/* Generate MAX_LEN bytes of "random" data deterministically. */

View File

@ -807,7 +807,7 @@ static void verify_stderr(int prog_fd, struct expected_msgs *msgs)
return;
buf = malloc(TEST_LOADER_LOG_BUF_SZ);
if (!ASSERT_OK_PTR(buf, "malloc"))
if (!ASSERT_NEQ(buf, NULL, "malloc"))
return;
ret = bpf_prog_stream_read(prog_fd, 2, buf, TEST_LOADER_LOG_BUF_SZ - 1,