From 92971e3755ac3d69f25b390b0f3e8c57943243ef Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 29 Sep 2020 09:23:13 -0400 Subject: [PATCH] maple_tree: Rename range_walk to _walk, clean up mas_node_walk Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 68 ++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index bc83da3ba676..0ed7192ae54a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2801,10 +2801,10 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, unsigned long *range_min, unsigned long *range_max) { unsigned long *pivots = ma_pivots(mas_mn(mas), type); - unsigned long min = mas->min, pivot = 0; + unsigned long min, pivot = 0; unsigned char i = mas_offset(mas); - bool ret = true; + min = mas_safe_min(mas, pivots, i); if (ma_is_dense(type)) { // Linear node. // What if mas->index != mas->last? @@ -2813,16 +2813,13 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, goto dense; } - if (i) - min = mas_safe_min(mas, pivots, i); - while(i < mt_slots[type]) { pivot = _mas_safe_pivot(mas, pivots, i, type); if (!pivot && i) { if (mas->max < mas->index) { - i = MAPLE_NODE_SLOTS; - ret = false; + mas_set_offset(mas, MAPLE_NODE_SLOTS); + return false; } pivot = mas->max; break; @@ -2836,12 +2833,10 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, } dense: - if (ret) { - *range_min = min; - *range_max = pivot; - } + *range_min = min; + *range_max = pivot; mas_set_offset(mas, i); - return ret; + return true; } /* @@ -2958,13 +2953,12 @@ static inline bool __mas_walk(struct ma_state *mas, unsigned long *range_min, next = mas_get_slot(mas, mas_offset(mas)); - if (unlikely(!next)) + if (!next) return false; // Traverse. mas->max = *range_max; mas->min = *range_min; - mas->node = next; mas_set_offset(mas, 0); } @@ -3348,16 +3342,12 @@ static inline bool mas_next_nentry(struct ma_state *mas, unsigned long max, { enum maple_type type = mte_node_type(mas->node); unsigned long pivot = mas->min; - unsigned long r_start = mas->min; + unsigned long r_start = *range_start; unsigned char offset = mas_offset(mas); - unsigned char count = mt_slots[type]; unsigned long *pivots = ma_pivots(mas_mn(mas), type); void **slots = ma_slots(mas_mn(mas), type); - void *entry; - r_start = mas_safe_min(mas, pivots, offset); - - while (offset < count) { + while (offset < mt_slots[type]) { pivot = _mas_safe_pivot(mas, pivots, offset, type); if (!pivot && offset) goto no_entry; @@ -3368,8 +3358,7 @@ static inline bool mas_next_nentry(struct ma_state *mas, unsigned long max, if (r_start > mas->max) goto no_entry; - entry = mas_slot(mas, slots, offset); - if (entry) + if (mas_slot(mas, slots, offset)) goto found; /* Ran over the limit, this is was the last slot to try */ @@ -3706,12 +3695,12 @@ done: } /* - * _mas_range_walk(): A walk that supports returning the range in which an + * _mas_walk(): A walk that supports returning the range in which an * index is located. * */ -static inline bool _mas_range_walk(struct ma_state *mas, - unsigned long *range_min, unsigned long *range_max) +static inline bool _mas_walk(struct ma_state *mas, unsigned long *range_min, + unsigned long *range_max) { void *entry = mas_start(mas); @@ -3731,15 +3720,10 @@ static inline bool _mas_range_walk(struct ma_state *mas, return __mas_walk(mas, range_min, range_max); } -static inline bool _mas_walk(struct ma_state *mas) +static inline int mas_dead_node(struct ma_state *mas, unsigned long index) { unsigned long range_max, range_min; - return _mas_range_walk(mas, &range_min, &range_max); -} - -static inline int mas_dead_node(struct ma_state *mas, unsigned long index) -{ if (!mas_searchable(mas)) return 0; @@ -3748,7 +3732,7 @@ static inline int mas_dead_node(struct ma_state *mas, unsigned long index) mas->index = index; mas->node = MAS_START; - _mas_walk(mas); + _mas_walk(mas, &range_min, &range_max); return 1; } @@ -4121,13 +4105,13 @@ no_gap: * range_min and range_max will be set accordingly. * */ -void *mas_range_load(struct ma_state *mas, unsigned long *range_min, +static inline void *mas_range_load(struct ma_state *mas, unsigned long *range_min, unsigned long *range_max) { void *entry = NULL; retry: - if (_mas_range_walk(mas, range_min, range_max)) { + if (_mas_walk(mas, range_min, range_max)) { unsigned char slot = MAPLE_NODE_SLOTS; if (mas_is_ptr(mas) && mas->last == 0) @@ -4142,12 +4126,6 @@ retry: goto retry; } - if (mas_is_none(mas)) - return NULL; - - if (!entry) - return NULL; - return entry; } @@ -4167,19 +4145,19 @@ static inline void *_mas_next(struct ma_state *mas, unsigned long limit, unsigned long *range_start) { void *entry = NULL; - unsigned long range_max; - if (!mas_searchable(mas)) - return NULL; if (mas_is_start(mas)) {// First run. + unsigned long range_max; + mas_start(mas); *range_start = 0; entry = mas_range_load(mas, range_start, &range_max); mas->last = range_max; if (entry) return entry; - } + } else if (!mas_searchable(mas)) + return NULL; return __mas_next(mas, limit, range_start); } @@ -4230,7 +4208,7 @@ void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, return NULL; rcu_read_lock(); - leaf = _mas_range_walk(&mas, &range_start, &range_end); + leaf = _mas_walk(&mas, &range_start, &range_end); slot = mas_offset(&mas); if (leaf == true && slot != MAPLE_NODE_SLOTS) entry = mas_get_slot(&mas, slot); -- 2.50.1