The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
@ 2026-05-12 10:13 Hongfu Li
  2026-05-12 10:33 ` David Hildenbrand (Arm)
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hongfu Li @ 2026-05-12 10:13 UTC (permalink / raw)
  To: jgg, leon, akpm, david, ljs, vbabka, rppt, surenb, mhocko, shuah
  Cc: linux-mm, linux-kselftest, linux-kernel, Hongfu Li

mmap() returns MAP_FAILED on error, not NULL.  The current check uses
!buffer->ptr, which evaluates to false when mmap() fails (since
MAP_FAILED is (void *)-1, not 0), so the error path is never taken.

Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
 tools/testing/selftests/mm/hmm-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
index 788689497e92..d72adba5c74e 100644
--- a/tools/testing/selftests/mm/hmm-tests.c
+++ b/tools/testing/selftests/mm/hmm-tests.c
@@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
 	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
 			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
-	if (!buffer->ptr)
+	if (buffer->ptr == MAP_FAILED)
 		return -1;
 
 	/* Apply THP hint if requested */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-12 14:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
2026-05-12 10:33 ` David Hildenbrand (Arm)
2026-05-12 11:13 ` Dev Jain
2026-05-12 12:21 ` Mike Rapoport
2026-05-12 12:57 ` Donet Tom
2026-05-12 14:06 ` Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox