[PATCH] mm/mmap: replace if (cond) BUG() with BUG_ON()
From: Alex Shi
Date: Fri Dec 11 2020 - 22:51:39 EST
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@xxxxxxxxxxxxxxxxx
Signed-off-by: Alex Shi <alex.shi@xxxxxxxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: linux-mm@xxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
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));
}
}
--
2.29.GIT