]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/mm: fix mmap() return value check in run_migration_benchmark
authorHongfu Li <lihongfu@kylinos.cn>
Tue, 12 May 2026 10:13:05 +0000 (18:13 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 2 Jun 2026 22:22:10 +0000 (15:22 -0700)
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.

Link: https://lore.kernel.org/20260512101305.139509-1-lihongfu@kylinos.cn
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Donet Tom <donettom@linux.ibm.com>
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/hmm-tests.c

index 77fb4c5d871bb8d034f65a473d745867e3f90e20..7a4daadfb0c84ccc42ce7336c25fcbad4f70360f 100644 (file)
@@ -2738,7 +2738,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 */