From patchwork Tue Jun 29 02:38:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12349077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBC14C11F66 for ; Tue, 29 Jun 2021 02:38:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8F79B61D0C for ; Tue, 29 Jun 2021 02:38:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F79B61D0C 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 E89BD8D00DA; Mon, 28 Jun 2021 22:38:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E61928D008F; Mon, 28 Jun 2021 22:38:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D02938D00DA; Mon, 28 Jun 2021 22:38:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id ADD018D008F for ; Mon, 28 Jun 2021 22:38:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A1BE11BCBF for ; Tue, 29 Jun 2021 02:38:40 +0000 (UTC) X-FDA: 78305203200.17.A12BF9F Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id 558528019373 for ; Tue, 29 Jun 2021 02:38:40 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6500E61D08; Tue, 29 Jun 2021 02:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1624934319; bh=ZRSPUSpvjZoajNQYqqfJL617rE2OaZ8w5ZtoKfiJ1Ls=; h=Date:From:To:Subject:In-Reply-To:From; b=rXXr/Aki1eTBhb002NPXdpakAQ6p2xfuNPNnxpfef+1ZMm7pr78xyatlyR24GrCb6 eO5hbs0bkb70I8ECxlqoOdR5yCbAezMgs1pg5i1/6/IXr6kSw70MX0YI7PC0Is1/Ul gcUqORe4p8IS0qivyF4qVs7XMNEMWuUqLMgyscL4= Date: Mon, 28 Jun 2021 19:38:39 -0700 From: Andrew Morton To: akpm@linux-foundation.org, david@redhat.com, gmjuareztello@gmail.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 101/192] mm/mmap.c: logic of find_vma_intersection repeated in __do_munmap Message-ID: <20210629023839.aYYiE3f-r%akpm@linux-foundation.org> In-Reply-To: <20210628193256.008961950a714730751c1423@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="rXXr/Aki"; dmarc=none; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: fss5bm154xyz31kaacbbrt9qsrn44n8j X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 558528019373 X-HE-Tag: 1624934320-6668 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: Gonzalo Matias Juarez Tello Subject: mm/mmap.c: logic of find_vma_intersection repeated in __do_munmap Logic of find_vma_intersection() is repeated in __do_munmap(). Also, prev is assigned a value before checking vma->vm_start >= end which might end up on a return statement making that assignment useless. Calling find_vma_intersection() checks that condition and returns NULL if no vma is found, hence only the !vma check is needed in __do_munmap(). Link: https://lkml.kernel.org/r/20210409162129.18313-1-gmjuareztello@gmail.com Signed-off-by: Gonzalo Matias Juarez Tello Reviewed-by: Andrew Morton Reviewed-by: David Hildenbrand Signed-off-by: Andrew Morton --- mm/mmap.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) --- a/mm/mmap.c~mm-mmapc-logic-of-find_vma_intersection-repeated-in-__do_munmap +++ a/mm/mmap.c @@ -2828,16 +2828,11 @@ int __do_munmap(struct mm_struct *mm, un */ arch_unmap(mm, start, end); - /* Find the first overlapping VMA */ - vma = find_vma(mm, start); + /* Find the first overlapping VMA where start < vma->vm_end */ + vma = find_vma_intersection(mm, start, end); if (!vma) return 0; prev = vma->vm_prev; - /* we have start < vma->vm_end */ - - /* if it doesn't overlap, we have nothing.. */ - if (vma->vm_start >= end) - return 0; /* * If we need to split any vma, do it now to save pain later.