From 6b84cece63107253a33ac361e34c28973dd9335e Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 5 Jul 2021 16:54:17 -0400 Subject: [PATCH] maple_tree: Change _mas_next to _mas_find Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 89 +++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 7e977ac2d632..ab6bd9e53e13 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4532,7 +4532,7 @@ done: } /* - * __mas_next() - Internal function to get the next entry. + * _mas_next() - Internal function to get the next entry. * @mas: The maple state * @limit: The maximum range start. * @@ -4543,7 +4543,7 @@ done: * * Return: the next entry or %NULL. */ -static inline void *__mas_next(struct ma_state *mas, unsigned long limit) +static inline void *_mas_next(struct ma_state *mas, unsigned long limit) { void *entry = NULL; struct maple_enode *prev_node = mas->node; @@ -5215,16 +5215,14 @@ retry: } /* - * _mas_next() - Finds the next entry and sets @mas->index and @mas->last to the - * range. + * _mas_find() - Finds the entry at @mas->index on MAS_START or the next entry + * and sets @mas->index and @mas->last to the range. * @mas: The maple state * @limit: The maximum value to check. - *. * * Return: Point to the next entry or %NULL - * */ -static void *_mas_next(struct ma_state *mas, unsigned long limit) +static void *_mas_find(struct ma_state *mas, unsigned long limit) { if (unlikely(mas_is_start(mas))) { /* First run */ @@ -5233,6 +5231,7 @@ static void *_mas_next(struct ma_state *mas, unsigned long limit) unsigned long range_start; mas_start(mas); + /* Retries on dead nodes handled by mas_range_load */ entry = mas_range_load(mas, &range_start, &range_max); mas->last = range_max; mas->index = range_start; @@ -5243,7 +5242,8 @@ static void *_mas_next(struct ma_state *mas, unsigned long limit) if (unlikely(!mas_searchable(mas))) return NULL; - return __mas_next(mas, limit); + /* Retries on dead nodes handled by _mas_next */ + return _mas_next(mas, limit); } /* @@ -5283,7 +5283,7 @@ void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, entry = NULL; while (mas_search_cont(&mas, range_start, max, entry)) { - entry = _mas_next(&mas, max); + entry = _mas_find(&mas, max); range_start = mas.index; if (!entry || xa_is_zero(entry)) entry = NULL; @@ -5598,10 +5598,12 @@ void *mas_next(struct ma_state *mas, unsigned long max) if (mas_is_start(mas)) { mas->index = ++mas->last; - return mas_find(mas, max); + /* Retries on dead nodes handled by _mas_find */ + return _mas_find(mas, max); } - return __mas_next(mas, max); + /* Retries on dead nodes handled by _mas_next */ + return _mas_next(mas, max); } EXPORT_SYMBOL_GPL(mas_next); @@ -5640,7 +5642,6 @@ EXPORT_SYMBOL_GPL(mt_next); */ void *mas_prev(struct ma_state *mas, unsigned long min) { - void *entry; if (!mas->index) { /* Nothing comes before 0 */ @@ -5648,22 +5649,23 @@ void *mas_prev(struct ma_state *mas, unsigned long min) return NULL; } + if (unlikely(mas_is_ptr(mas))) + return NULL; + if (mas_is_none(mas) || mas_is_paused(mas)) mas->node = MAS_START; - if (!mas_searchable(mas)) - return NULL; - if (mas_is_start(mas)) { + void *entry; + + mas->last = --mas->index; mas_start(mas); - mas_walk(mas); + entry = mas_walk(mas); + if (entry) + return entry; } - do { - entry = _mas_prev(mas, min); - } while (!mas_is_none(mas) && !entry); - - return entry; + return _mas_prev(mas, min); } EXPORT_SYMBOL_GPL(mas_prev); @@ -5705,24 +5707,6 @@ void mas_pause(struct ma_state *mas) } EXPORT_SYMBOL_GPL(mas_pause); -/* - * mas_resume_fwd() - resume a forward search. - * @mas: The maple state - * - * Returns: 0 on success, -EFAULT on overflow. - */ -static inline int mas_resume_fwd(struct ma_state *mas) { - if (mas_is_paused(mas)) { - if (unlikely(mas->last == ULONG_MAX)) { - mas->node = MAS_NONE; - return -EFAULT; - } - mas->node = MAS_START; - mas->index = ++mas->last; - } - return 0; -} - /* * mas_find: If mas->node == MAS_START, find the first * non-NULL entry >= mas->index. @@ -5738,27 +5722,16 @@ static inline int mas_resume_fwd(struct ma_state *mas) { */ void *mas_find(struct ma_state *mas, unsigned long max) { - void *entry = NULL; - bool first = false; - unsigned long index = mas->index; - - if (mas_is_start(mas) && (mas->index <= max)) - first = true; - else if (mas_resume_fwd(mas)) - return NULL; - -retry: - while (mas_search_cont(mas, mas->index, max, entry)) - entry = _mas_next(mas, max); - - if (unlikely(mas_dead_node(mas, index))) { - if (first) - mas->node = MAS_START; - - goto retry; + if (mas_is_paused(mas)) { + if (unlikely(mas->last == ULONG_MAX)) { + mas->node = MAS_NONE; + return NULL; + } + mas->node = MAS_START; + mas->index = ++mas->last; } - return entry; + return _mas_find(mas, max); } EXPORT_SYMBOL_GPL(mas_find); -- 2.50.1