From 2bd30b8dc75b823dd7bbef9d7bc68e1fd7ecee5c Mon Sep 17 00:00:00 2001 From: Sang-Heon Jeon Date: Mon, 24 Aug 2026 01:18:14 +0900 Subject: coccinelle: alloc_cast: drop removed allocators - pci_alloc_consistent() and pci_zalloc_consistent() were removed by commit 7968778914e5 ("PCI: Remove the deprecated "pci-dma-compat.h" API") - kmem_alloc() was removed by commit f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()") - kmem_zalloc() was removed by commit 10634530f7ba ("xfs: convert kmem_zalloc() to kzalloc()") - kmem_zone_alloc() and kmem_zone_zalloc() were removed by commit bae633a4a283 ("xfs: remove xfs_zone_{alloc,zalloc} helpers") So drop them from the rules. No functional change. Signed-off-by: Sang-Heon Jeon Signed-off-by: Julia Lawall --- mm/interval_tree.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 mm/interval_tree.c (limited to 'mm/interval_tree.c') diff --git a/mm/interval_tree.c b/mm/interval_tree.c new file mode 100644 index 000000000..3ae9e106d --- /dev/null +++ b/mm/interval_tree.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * mm/interval_tree.c - interval tree for address_space->i_mmap and + * anon_vma->rb_root + * + * Copyright (C) 2012, Michel Lespinasse + */ + +#include +#include +#include +#include + +/* File-backed interval tree (address_space->i_mmap) */ + +INTERVAL_TREE_DEFINE(struct vm_area_struct, shared.rb, + pgoff_t, shared.rb_subtree_last, + vma_start_pgoff, vma_last_pgoff, static, + __mapping_rmap_tree) + +void mapping_rmap_tree_insert(struct vm_area_struct *vma, + struct address_space *mapping) +{ + __mapping_rmap_tree_insert(vma, &mapping->i_mmap); +} + +/* Insert vma immediately after prev in the interval tree */ +void mapping_rmap_tree_insert_after(struct vm_area_struct *vma, + struct vm_area_struct *prev, + struct address_space *mapping) +{ + struct rb_node **link; + struct vm_area_struct *parent; + const pgoff_t pgoff_last = vma_last_pgoff(vma); + + VM_WARN_ON_ONCE_VMA(vma_start_pgoff(vma) != vma_start_pgoff(prev), vma); + + if (!prev->shared.rb.rb_right) { + parent = prev; + link = &prev->shared.rb.rb_right; + } else { + parent = rb_entry(prev->shared.rb.rb_right, + struct vm_area_struct, shared.rb); + if (parent->shared.rb_subtree_last < pgoff_last) + parent->shared.rb_subtree_last = pgoff_last; + while (parent->shared.rb.rb_left) { + parent = rb_entry(parent->shared.rb.rb_left, + struct vm_area_struct, shared.rb); + if (parent->shared.rb_subtree_last < pgoff_last) + parent->shared.rb_subtree_last = pgoff_last; + } + link = &parent->shared.rb.rb_left; + } + + vma->shared.rb_subtree_last = pgoff_last; + rb_link_node(&vma->shared.rb, &parent->shared.rb, link); + rb_insert_augmented(&vma->shared.rb, &mapping->i_mmap.rb_root, + &__mapping_rmap_tree_augment); +} + +void mapping_rmap_tree_remove(struct vm_area_struct *vma, + struct address_space *mapping) +{ + __mapping_rmap_tree_remove(vma, &mapping->i_mmap); +} + +struct vm_area_struct * +mapping_rmap_tree_iter_first(struct address_space *mapping, + pgoff_t pgoff_start, pgoff_t pgoff_last) +{ + return __mapping_rmap_tree_iter_first(&mapping->i_mmap, + pgoff_start, pgoff_last); +} + +struct vm_area_struct * +mapping_rmap_tree_iter_next(struct vm_area_struct *vma, + pgoff_t pgoff_start, pgoff_t pgoff_last) +{ + return __mapping_rmap_tree_iter_next(vma, pgoff_start, pgoff_last); +} + +/* Anonymous interval tree (anon_vma->rb_root) */ + +static pgoff_t avc_start_pgoff(struct anon_vma_chain *avc) +{ + return vma_start_pgoff(avc->vma); +} + +static pgoff_t avc_last_pgoff(struct anon_vma_chain *avc) +{ + return vma_last_pgoff(avc->vma); +} + +INTERVAL_TREE_DEFINE(struct anon_vma_chain, rb, pgoff_t, rb_subtree_last, + avc_start_pgoff, avc_last_pgoff, + static, __anon_rmap_tree) + +void anon_rmap_tree_insert(struct anon_vma_chain *avc, + struct anon_vma *anon_vma) +{ +#ifdef CONFIG_DEBUG_VM_RB + avc->cached_vma_start = avc_start_pgoff(avc); + avc->cached_vma_last = avc_last_pgoff(avc); +#endif + __anon_rmap_tree_insert(avc, &anon_vma->rb_root); +} + +void anon_rmap_tree_remove(struct anon_vma_chain *avc, + struct anon_vma *anon_vma) +{ + __anon_rmap_tree_remove(avc, &anon_vma->rb_root); +} + +struct anon_vma_chain * +anon_rmap_tree_iter_first(struct anon_vma *anon_vma, + pgoff_t pgoff_start, pgoff_t pgoff_last) +{ + return __anon_rmap_tree_iter_first(&anon_vma->rb_root, + pgoff_start, pgoff_last); +} + +struct anon_vma_chain * +anon_rmap_tree_iter_next(struct anon_vma_chain *avc, + pgoff_t pgoff_start, pgoff_t pgoff_last) +{ + return __anon_rmap_tree_iter_next(avc, pgoff_start, pgoff_last); +} + +#ifdef CONFIG_DEBUG_VM_RB +void anon_rmap_tree_verify(struct anon_vma_chain *avc) +{ + WARN_ON_ONCE(avc->cached_vma_start != avc_start_pgoff(avc)); + WARN_ON_ONCE(avc->cached_vma_last != avc_last_pgoff(avc)); +} +#endif -- cgit v1.3.1