Return error code directly for addr is not PAGE_SIZE aligned or beyond TASK_SIZE, no need to check these cases in caller. Signed-off-by: Chen Wandun <chenwandun@xxxxxxxxxx> --- mm/shmem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 7419ab219b97..48b7172f81d6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2142,10 +2142,10 @@ unsigned long shmem_get_unmapped_area(struct file *file, return addr; if (IS_ERR_VALUE(addr)) return addr; - if (addr & ~PAGE_MASK) - return addr; + if (offset_in_page(addr)) + return -EINVAL; if (addr > TASK_SIZE - len) - return addr; + return -ENOMEM; if (shmem_huge == SHMEM_HUGE_DENY) return addr; @@ -2196,7 +2196,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, inflated_addr = get_area(NULL, uaddr, inflated_len, 0, flags); if (IS_ERR_VALUE(inflated_addr)) return addr; - if (inflated_addr & ~PAGE_MASK) + if (offset_in_page(inflated_addr)) return addr; inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1); -- 2.25.1