[dpdk-dev,v3] eal/linuxapp: check mmap return value MAP_FAILED

Message ID 20170828214912.133503-1-seth.howell@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Seth Howell Aug. 28, 2017, 9:49 p.m. UTC
  If mmap fails, it will return the value MAP_FAILED. Checking for this
return code allows us to properly identify mmap failures and report
them as such to the calling function.

Signed-off-by: Seth Howell <seth.howell@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Sergio Gonzalez Monroy Aug. 29, 2017, 8:31 a.m. UTC | #1
On 28/08/2017 22:49, Seth Howell wrote:
> If mmap fails, it will return the value MAP_FAILED. Checking for this
> return code allows us to properly identify mmap failures and report
> them as such to the calling function.
>
> Signed-off-by: Seth Howell <seth.howell@intel.com>
> ---
>   lib/librte_eal/linuxapp/eal/eal_memory.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
> index 5279128..63fec29 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> @@ -716,6 +716,8 @@ create_shared_memory(const char *filename, const size_t mem_size)
>   	}
>   	retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>   	close(fd);
> +	if (retval == MAP_FAILED)
> +		return NULL;
>   	return retval;
>   }
>   

Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
  
Thomas Monjalon Oct. 9, 2017, 9:18 p.m. UTC | #2
29/08/2017 10:31, Sergio Gonzalez Monroy:
> On 28/08/2017 22:49, Seth Howell wrote:
> > If mmap fails, it will return the value MAP_FAILED. Checking for this
> > return code allows us to properly identify mmap failures and report
> > them as such to the calling function.
> >
> > Signed-off-by: Seth Howell <seth.howell@intel.com>
> 
> Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5279128..63fec29 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -716,6 +716,8 @@  create_shared_memory(const char *filename, const size_t mem_size)
 	}
 	retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	close(fd);
+	if (retval == MAP_FAILED)
+		return NULL;
 	return retval;
 }