Re: [PATCH v2] selftests/mm: Fix incorrect mmap() error handling with NULL instead of MAP_FAILED
From: Hongfu Li
Date: Wed May 13 2026 - 07:19:39 EST
> > mmap() returns MAP_FAILED, which is defined as (void *)-1, on error,
> > not NULL. Several selftests incorrectly check the return value of
> > mmap() using !ptr or ptr == NULL, which would erroneously treat
> > MAP_FAILED as a valid pointer since MAP_FAILED is non-zero and
> > non-NULL. This can lead to segfaults when mmap() actually fails
> > under memory pressure.
> >
> > Signed-off-by: Hongfu Li <lihongfu@xxxxxxxxxx>
> > Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
>
> You forgot my tag :)
>
> Also, please do not send a respin right away if you can, multiple revisions in
> one day can be tricky to deal with.
>
> As per David's points - please update the commit message to reflect the fact
> you've added a missing assert too and replace the (void *)-1 with MAP_FAILED.
Thanks for the reminder. I will avoid sending a quick respin within the
same day, and I'll update the commit message to mention the added assert
check, and replace (void *)-1 with MAP_FAILED in the next version.