From patchwork Sun Dec 1 01:51:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11268249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EBE6C112B for ; Sun, 1 Dec 2019 01:51:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B817D206F0 for ; Sun, 1 Dec 2019 01:51:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="prLbjhyY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B817D206F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B788F6B029E; Sat, 30 Nov 2019 20:51:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B50256B02A0; Sat, 30 Nov 2019 20:51:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8CB66B02A1; Sat, 30 Nov 2019 20:51:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 912806B029E for ; Sat, 30 Nov 2019 20:51:05 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 4631A2A87 for ; Sun, 1 Dec 2019 01:51:05 +0000 (UTC) X-FDA: 76214894490.13.skirt61_971a12c38052 X-Spam-Summary: 2,0,0,a68f7230201e72be,d41d8cd98f00b204,akpm@linux-foundation.org,:akpm@linux-foundation.org:cai@lca.pw:jglisse@redhat.com:khlebnikov@yandex-team.ru:kirill.shutemov@linux.intel.com::mhocko@suse.com:mike.kravetz@oracle.com:mm-commits@vger.kernel.org:pugaowei@gmail.com:richardw.yang@linux.intel.com:riel@surriel.com:shakeelb@google.com:torvalds@linux-foundation.org:vbabka@suse.cz,RULES_HIT:41:152:355:379:800:960:967:973:988:989:1260:1263:1277:1311:1313:1314:1345:1381:1431:1437:1513:1515:1516:1518:1521:1535:1543:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2525:2559:2563:2682:2685:2859:2899:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3608:3865:3866:3867:3868:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6119:6261:6653:6737:7514:7576:7875:7903:8599:9025:9036:9207:9545:10004:10400:10913:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12783:12986:13255:13846:14181 :14721:1 X-HE-Tag: skirt61_971a12c38052 X-Filterd-Recvd-Size: 5270 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Sun, 1 Dec 2019 01:51:04 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A8CB3206E1; Sun, 1 Dec 2019 01:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575165064; bh=Wgq/am9Z3fF8Hjbp64KlkRUoi5mtSEkhiDtvj6Kvpvs=; h=Date:From:To:Subject:From; b=prLbjhyYnFunYc5g6QkwzI8EL4Yyf69euaHiyYDWyjf7n9e6EpM86pead5nsC0fXC TDZtJtWODL0iyGp6jNY8mDNiNipvlK/38d0EtucAZakuTSbxJfH+EoKvCvzaxNxZwN gGIMg9fp9WFCxnjQyKtcsbY8ZBnXsaU3k+ceVomM= Date: Sat, 30 Nov 2019 17:51:03 -0800 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, cai@lca.pw, jglisse@redhat.com, khlebnikov@yandex-team.ru, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, mhocko@suse.com, mike.kravetz@oracle.com, mm-commits@vger.kernel.org, pugaowei@gmail.com, richardw.yang@linux.intel.com, riel@surriel.com, shakeelb@google.com, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 036/158] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area Message-ID: <20191201015103.QxO3Ou2PX%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Gaowei Pu Subject: mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area get_unmapped_area() returns an address or -errno on failure. Historically we have checked for the failure by offset_in_page() which is correct but quite hard to read. Newer code started using IS_ERR_VALUE which is much easier to read. Convert remaining users of offset_in_page as well. [mhocko@suse.com: rewrite changelog] [mhocko@kernel.org: fix mremap.c and uprobes.c sites also] Link: http://lkml.kernel.org/r/20191012102512.28051-1-pugaowei@gmail.com Signed-off-by: Gaowei Pu Reviewed-by: Andrew Morton Acked-by: Michal Hocko Cc: Vlastimil Babka Cc: Wei Yang Cc: Konstantin Khlebnikov Cc: Kirill A. Shutemov Cc: "Jérôme Glisse" Cc: Mike Kravetz Cc: Rik van Riel Cc: Qian Cai Cc: Shakeel Butt Signed-off-by: Andrew Morton --- kernel/events/uprobes.c | 2 +- mm/mmap.c | 9 +++++---- mm/mremap.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) --- a/kernel/events/uprobes.c~mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area +++ a/kernel/events/uprobes.c @@ -1457,7 +1457,7 @@ static int xol_add_vma(struct mm_struct /* Try to map as high as possible, this is only a hint. */ area->vaddr = get_unmapped_area(NULL, TASK_SIZE - PAGE_SIZE, PAGE_SIZE, 0, 0); - if (area->vaddr & ~PAGE_MASK) { + if (IS_ERR_VALUE(area->vaddr)) { ret = area->vaddr; goto fail; } --- a/mm/mmap.c~mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area +++ a/mm/mmap.c @@ -1417,7 +1417,7 @@ unsigned long do_mmap(struct file *file, * that it represents a valid section of the address space. */ addr = get_unmapped_area(file, addr, len, pgoff, flags); - if (offset_in_page(addr)) + if (IS_ERR_VALUE(addr)) return addr; if (flags & MAP_FIXED_NOREPLACE) { @@ -2981,15 +2981,16 @@ static int do_brk_flags(unsigned long ad struct rb_node **rb_link, *rb_parent; pgoff_t pgoff = addr >> PAGE_SHIFT; int error; + unsigned long mapped_addr; /* Until we need other flags, refuse anything except VM_EXEC. */ if ((flags & (~VM_EXEC)) != 0) return -EINVAL; flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; - error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED); - if (offset_in_page(error)) - return error; + mapped_addr = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED); + if (IS_ERR_VALUE(mapped_addr)) + return mapped_addr; error = mlock_future_check(mm, mm->def_flags, len); if (error) --- a/mm/mremap.c~mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area +++ a/mm/mremap.c @@ -558,7 +558,7 @@ static unsigned long mremap_to(unsigned ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT), map_flags); - if (offset_in_page(ret)) + if (IS_ERR_VALUE(ret)) goto out1; ret = move_vma(vma, addr, old_len, new_len, new_addr, locked, uf, @@ -706,7 +706,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, a vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT), map_flags); - if (offset_in_page(new_addr)) { + if (IS_ERR_VALUE(new_addr)) { ret = new_addr; goto out; }