test_seal_zero_address() uses mmap() with MAP_FIXED to map at address 0,
but only checks if the return value equals 0. If mmap() fails, it returns
MAP_FAILED ((void *)-1), not 0. The existing check FAIL_TEST_IF_FALSE(ptr == 0)
would pass when ptr == -1 (since -1 != 0 is true), causing the test to
continue with an invalid pointer.
Add a check for MAP_FAILED before verifying ptr == 0, consistent with all
other mmap() checks in this file which use FAIL_TEST_IF_FALSE(ptr != (void
*)-1).
Fixes: 4926c7a52de7 ("selftest mm/mseal memory sealing")
Signed-off-by: longlong yan <[email protected]>
---
tools/testing/selftests/mm/mseal_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/mseal_test.c
b/tools/testing/selftests/mm/mseal_test.c
index faad4833366a..a6ecc81c6aa0 100644
--- a/tools/testing/selftests/mm/mseal_test.c
+++ b/tools/testing/selftests/mm/mseal_test.c
@@ -482,7 +482,7 @@ static void test_seal_zero_address(void)
/* use mmap to change protection. */
ptr = mmap(0, size, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
- FAIL_TEST_IF_FALSE(ptr == 0);
+ FAIL_TEST_IF_FALSE(ptr == (void *)-1);
size = get_vma_size(ptr, &prot);
FAIL_TEST_IF_FALSE(size == 4 * page_size);
--
2.43.0