From patchwork Sat Dec 12 03:26:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 11969867 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT 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 BA55FC4361B for ; Sat, 12 Dec 2020 03:26:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE3B223332 for ; Sat, 12 Dec 2020 03:26:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE3B223332 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 107F66B0036; Fri, 11 Dec 2020 22:26:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BB496B005C; Fri, 11 Dec 2020 22:26:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F106A6B005D; Fri, 11 Dec 2020 22:26:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id DB63B6B0036 for ; Fri, 11 Dec 2020 22:26:35 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A3B163652 for ; Sat, 12 Dec 2020 03:26:35 +0000 (UTC) X-FDA: 77583192750.17.gate28_2f04fc927406 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 8C408180D0194 for ; Sat, 12 Dec 2020 03:26:35 +0000 (UTC) X-HE-Tag: gate28_2f04fc927406 X-Filterd-Recvd-Size: 3753 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Sat, 12 Dec 2020 03:26:34 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0UIIAwQ4_1607743587; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UIIAwQ4_1607743587) by smtp.aliyun-inc.com(127.0.0.1); Sat, 12 Dec 2020 11:26:30 +0800 From: Alex Shi To: Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/mmap: replace if (cond) BUG() with BUG_ON() Date: Sat, 12 Dec 2020 11:26:26 +0800 Message-Id: <1607743586-80303-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607743586-80303-1-git-send-email-alex.shi@linux.alibaba.com> References: <1607743586-80303-1-git-send-email-alex.shi@linux.alibaba.com> 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: coccinelle reports some warnings: WARNING: Use BUG_ON instead of if condition followed by BUG. It could be fixed by BUG_ON(). Reported-by: abaci@linux.alibaba.com Signed-off-by: Alex Shi Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Reported-by: abaci@linux.alibaba.com Signed-off-by: Alex Shi --- mm/mmap.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 8144fc3c5a78..2dab93dedae6 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -712,9 +712,8 @@ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) struct vm_area_struct *prev; struct rb_node **rb_link, *rb_parent; - if (find_vma_links(mm, vma->vm_start, vma->vm_end, - &prev, &rb_link, &rb_parent)) - BUG(); + BUF_ON(find_vma_links(mm, vma->vm_start, vma->vm_end, + &prev, &rb_link, &rb_parent)); __vma_link(mm, vma, prev, rb_link, rb_parent); mm->map_count++; } @@ -3585,9 +3584,8 @@ static void vm_lock_anon_vma(struct mm_struct *mm, struct anon_vma *anon_vma) * can't change from under us thanks to the * anon_vma->root->rwsem. */ - if (__test_and_set_bit(0, (unsigned long *) - &anon_vma->root->rb_root.rb_root.rb_node)) - BUG(); + BUG_ON(__test_and_set_bit(0, (unsigned long *) + &anon_vma->root->rb_root.rb_root.rb_node)); } } @@ -3603,8 +3601,7 @@ static void vm_lock_mapping(struct mm_struct *mm, struct address_space *mapping) * mm_all_locks_mutex, there may be other cpus * changing other bitflags in parallel to us. */ - if (test_and_set_bit(AS_MM_ALL_LOCKS, &mapping->flags)) - BUG(); + BUG_ON(test_and_set_bit(AS_MM_ALL_LOCKS, &mapping->flags)); down_write_nest_lock(&mapping->i_mmap_rwsem, &mm->mmap_lock); } } @@ -3701,9 +3698,8 @@ static void vm_unlock_anon_vma(struct anon_vma *anon_vma) * can't change from under us until we release the * anon_vma->root->rwsem. */ - if (!__test_and_clear_bit(0, (unsigned long *) - &anon_vma->root->rb_root.rb_root.rb_node)) - BUG(); + BUG_ON(!__test_and_clear_bit(0, (unsigned long *) + &anon_vma->root->rb_root.rb_root.rb_node)); anon_vma_unlock_write(anon_vma); } } @@ -3716,9 +3712,7 @@ static void vm_unlock_mapping(struct address_space *mapping) * because we hold the mm_all_locks_mutex. */ i_mmap_unlock_write(mapping); - if (!test_and_clear_bit(AS_MM_ALL_LOCKS, - &mapping->flags)) - BUG(); + BUG_ON(!test_and_clear_bit(AS_MM_ALL_LOCKS, &mapping->flags)); } }