[PATCH] mips/mm/mmap: fix the wrong return value from syscall mmap() on mips architecture

From: Yang Yi
Date: Wed Jul 25 2018 - 03:34:20 EST

According to the latest POSIX standard defined in IEEE Std 1003.1-2017,
the errno should be set to ENOMEM instead of EINVAL when mmap into
high region address which exceeds the address boundary of a process.

The corresponding description of IEEE Std 1003.1-2017 is as follows:

The mmap() function shall fail if:
MAP_FIXED was specified, and the range [addr,addr+len)
exceeds that allowed for the address space of a process;
or, if MAP_FIXED was not specified and there is insufficient
room in the address space to effect the mapping.

Signed-off-by: Yang Yi <yang.yi@xxxxxxxxxx>
Signed-off-by: Hailong Liu <liu.hailong6@xxxxxxxxxx>
Reviewed-by: Jiang Biao <jiang.biao2@xxxxxxxxxx>
arch/mips/mm/mmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
index 2f616eb..c47059c 100755
--- a/arch/mips/mm/mmap.c
+++ b/arch/mips/mm/mmap.c
@@ -69,7 +69,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
if (flags & MAP_FIXED) {
/* Even MAP_FIXED mappings must reside within TASK_SIZE */
if (TASK_SIZE - len < addr)
- return -EINVAL;
+ return -ENOMEM;

* We do not accept a shared mapping if it would violate