Skip to content

Commit 71384f8

Browse files
kevin-brodsky-armakpm00
authored andcommitted
selftests/mm: fix -Warray-bounds warnings in pkey_sighandler_tests
GCC doesn't like dereferencing a pointer set to 0x1 (when building at -O2): pkey_sighandler_tests.c:166:9: warning: array subscript 0 is outside array bounds of 'int[0]' [-Warray-bounds=] 166 | *(int *) (0x1) = 1; | ^~~~~~~~~~~~~~ cc1: note: source object is likely at address zero Using NULL instead seems to make it happy. This should make no difference in practice (SIGSEGV with SEGV_MAPERR will be the outcome regardless), we just need to update the expected si_addr. [[email protected]: fix clang dereferencing-null issue] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kevin Brodsky <[email protected]> Cc: Aruna Ramakrishna <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Joey Gouly <[email protected]> Cc: Keith Lucas <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Shuah Khan <[email protected]> Cc: kernel test robot <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5b6b279 commit 71384f8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tools/testing/selftests/mm/pkey_sighandler_tests.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static void *thread_segv_with_pkey0_disabled(void *ptr)
163163
__write_pkey_reg(pkey_reg_restrictive_default());
164164

165165
/* Segfault (with SEGV_MAPERR) */
166-
*(int *) (0x1) = 1;
166+
*(volatile int *)NULL = 1;
167167
return NULL;
168168
}
169169

@@ -179,7 +179,6 @@ static void *thread_segv_pkuerr_stack(void *ptr)
179179
static void *thread_segv_maperr_ptr(void *ptr)
180180
{
181181
stack_t *stack = ptr;
182-
int *bad = (int *)1;
183182
u64 pkey_reg;
184183

185184
/*
@@ -195,7 +194,7 @@ static void *thread_segv_maperr_ptr(void *ptr)
195194
__write_pkey_reg(pkey_reg);
196195

197196
/* Segfault */
198-
*bad = 1;
197+
*(volatile int *)NULL = 1;
199198
syscall_raw(SYS_exit, 0, 0, 0, 0, 0, 0);
200199
return NULL;
201200
}
@@ -234,7 +233,7 @@ static void test_sigsegv_handler_with_pkey0_disabled(void)
234233

235234
ksft_test_result(siginfo.si_signo == SIGSEGV &&
236235
siginfo.si_code == SEGV_MAPERR &&
237-
siginfo.si_addr == (void *)1,
236+
siginfo.si_addr == NULL,
238237
"%s\n", __func__);
239238
}
240239

@@ -349,7 +348,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void)
349348

350349
ksft_test_result(siginfo.si_signo == SIGSEGV &&
351350
siginfo.si_code == SEGV_MAPERR &&
352-
siginfo.si_addr == (void *)1,
351+
siginfo.si_addr == NULL,
353352
"%s\n", __func__);
354353
}
355354

0 commit comments

Comments
 (0)