tools/testing/selftests/mm/hmm-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
On Tue, 12 May 2026 18:13:05 +0800 Hongfu Li <lihongfu@kylinos.cn> wrote: > 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. Good catch, thank you! > > Signed-off-by: Hongfu Li <lihongfu@kylinos.cn> Reviewed-by: SeongJae Park <sj@kernel.org> Thanks, SJ [...]
On Tue, May 12, 2026 at 06:13:05PM +0800, Hongfu Li wrote: > 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> LGTM, so: Reviewed-by: Lorenzo Stoakes <ljs@kernel.org> > --- > 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 >
On 5/12/26 3:43 PM, Hongfu Li wrote: > 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> LGTM Reviewed-by: Donet Tom <donettom@linux.ibm.com> > --- > 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 */
On Tue, May 12, 2026 at 06:13:05PM +0800, Hongfu Li wrote: > 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> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> > --- > 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 > -- Sincerely yours, Mike.
On 12/05/26 3:43 pm, Hongfu Li wrote: > 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> > --- Reviewed-by: Dev Jain <dev.jain@arm.com> > 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 */
On 5/12/26 12:13, Hongfu Li wrote: > 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 */ Acked-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David
© 2016 - 2026 Red Hat, Inc.