From: Liam R. Howlett Date: Tue, 9 Nov 2021 20:01:24 +0000 (-0500) Subject: maple_tree: remove _mt_find() and add mt_find_after() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=38f3686a29aa2dce3c6c3762d9ea93c36d79f1cd;p=users%2Fjedix%2Flinux-maple.git maple_tree: remove _mt_find() and add mt_find_after() Signed-off-by: Liam R. Howlett --- diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 6fbe7e0d7a6c..80e947d68e3d 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -510,8 +510,8 @@ static inline void mt_set_in_rcu(struct maple_tree *mt) } void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max); -void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, - bool start); +void *mt_find_after(struct maple_tree *mt, unsigned long *index, + unsigned long max); void *mt_prev(struct maple_tree *mt, unsigned long index, unsigned long min); void *mt_next(struct maple_tree *mt, unsigned long index, unsigned long max); @@ -521,8 +521,8 @@ void *mt_next(struct maple_tree *mt, unsigned long index, unsigned long max); * Note: Will not return the zero entry. */ #define mt_for_each(tree, entry, index, max) \ - for (entry = _mt_find(tree, &index, max, true); \ - entry; entry = _mt_find(tree, &index, max, false)) + for (entry = mt_find(tree, &index, max); \ + entry; entry = mt_find_after(tree, &index, max)) #ifdef CONFIG_DEBUG_MAPLE_TREE diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 46b86756914d..61013cd8a5bf 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5504,68 +5504,6 @@ no_gap: return -EBUSY; } -/* - * _mt_find() - Search from start up until an entry is found. - * @mt: The maple tree - * @*index: Pointer which contains the start location of the search - * @max: The maximum value to check - * @start: If this is the first time being called or not. - *. Does not return the zero entry. Handles locking. - * Return: the entry or %NULL - */ -void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, - bool start) -{ - unsigned long range_start = 0, range_end = 0; - void *entry = NULL; - bool leaf; -#ifdef CONFIG_DEBUG_MAPLE_TREE - unsigned long copy = *index; -#endif - - MA_STATE(mas, mt, *index, *index); - - if ((*index) > max) - return NULL; - - if (!start && !(*index)) - return NULL; - - rcu_read_lock(); - leaf = _mas_walk(&mas, &range_start, &range_end); - if (leaf == true && mas.offset != MAPLE_NODE_SLOTS) - entry = mas_get_slot(&mas, mas.offset); - - mas.last = range_end; - if (entry && !xa_is_zero(entry)) { - rcu_read_unlock(); - goto done; - } - - mas.index = range_start; - while (mas_searchable(&mas) && (mas.index < max)) { - entry = mas_next_entry(&mas, max); - if (likely(entry && !xa_is_zero(entry))) - break; - } - rcu_read_unlock(); - - if (unlikely(xa_is_zero(entry))) - entry = NULL; -done: - if (likely(entry)) { - *index = mas.last + 1; -#ifdef CONFIG_DEBUG_MAPLE_TREE - if ((*index) && (*index) <= copy) - printk("index not increased! %lx <= %lx\n", - *index, copy); - MT_BUG_ON(mt, (*index) && ((*index) <= copy)); -#endif - } - - return entry; -} - /* * mas_dead_leaves() - Mark all leaves of a node as dead. * @mas: The maple state @@ -6441,10 +6379,74 @@ EXPORT_SYMBOL(mtree_destroy); */ void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max) { - return _mt_find(mt, index, max, true); + unsigned long range_start = 0, range_end = 0; + void *entry = NULL; + bool leaf; +#ifdef CONFIG_DEBUG_MAPLE_TREE + unsigned long copy = *index; +#endif + + MA_STATE(mas, mt, *index, *index); + + if ((*index) > max) + return NULL; + + rcu_read_lock(); + leaf = _mas_walk(&mas, &range_start, &range_end); + if (leaf == true && mas.offset != MAPLE_NODE_SLOTS) + entry = mas_get_slot(&mas, mas.offset); + + mas.last = range_end; + if (entry && !xa_is_zero(entry)) { + rcu_read_unlock(); + goto done; + } + + mas.index = range_start; + while (mas_searchable(&mas) && (mas.index < max)) { + entry = mas_next_entry(&mas, max); + if (likely(entry && !xa_is_zero(entry))) + break; + } + rcu_read_unlock(); + + if (unlikely(xa_is_zero(entry))) + entry = NULL; +done: + if (likely(entry)) { + *index = mas.last + 1; +#ifdef CONFIG_DEBUG_MAPLE_TREE + if ((*index) && (*index) <= copy) + printk("index not increased! %lx <= %lx\n", + *index, copy); + MT_BUG_ON(mt, (*index) && ((*index) <= copy)); +#endif + } + + return entry; } EXPORT_SYMBOL(mt_find); +/* + * mt_find_after() - Search from the start up until an entry is found. + * @mt: The maple tree + * @*index: Pointer which contains the start location of the search + * @max: The maximum value to check + * + * Handles locking, detects wrapping on *index == 0 + * + * Return: The entry at or after the @*index or %NULL + */ +void *mt_find_after(struct maple_tree *mt, unsigned long *index, + unsigned long max) +{ + if (!(*index)) + return NULL; + + return mt_find(mt, index, max); +} +EXPORT_SYMBOL(mt_find_after); + #ifdef CONFIG_DEBUG_MAPLE_TREE atomic_t maple_tree_tests_run; EXPORT_SYMBOL_GPL(maple_tree_tests_run);