[1/2] eal: fix mmap fail regarded as success
Checks
Commit Message
The map_shared_memory() function should treat mmap MAP_FAILED as NULL
because callers compare it with NULL to determine whether the map is
failed.
Fixes: 764bf26873b9 ("add FreeBSD support")
Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/freebsd/eal_hugepage_info.c | 2 +-
lib/eal/linux/eal_hugepage_info.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On Mon, Feb 6, 2023 at 11:59 AM Chengwen Feng <fengchengwen@huawei.com> wrote:
>
> The map_shared_memory() function should treat mmap MAP_FAILED as NULL
> because callers compare it with NULL to determine whether the map is
> failed.
>
> Fixes: 764bf26873b9 ("add FreeBSD support")
> Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
@@ -33,7 +33,7 @@ map_shared_memory(const char *filename, const size_t mem_size, int flags)
}
retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
- return retval;
+ return retval == MAP_FAILED ? NULL : retval;
}
static void *
@@ -50,7 +50,7 @@ map_shared_memory(const char *filename, const size_t mem_size, int flags)
retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
close(fd);
- return retval;
+ return retval == MAP_FAILED ? NULL : retval;
}
static void *