From d45649090a7d09459b24d6d4d6167e67e5fcbd9a Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 17 Jul 2020 20:46:38 -0400 Subject: [PATCH] maple_tree: Add helper for lower bound Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0c56767f5591..eb1ad58669fa 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -494,6 +494,7 @@ static inline unsigned long _mas_get_safe_pivot(const struct ma_state *mas, return _mte_get_pivot(mas->node, slot, type); } + /** Private * mas_get_safe_pivot() - Return the pivot or the mas->max. * @@ -507,6 +508,15 @@ static inline unsigned long mas_get_safe_pivot(const struct ma_state *mas, return _mas_get_safe_pivot(mas, slot, type); } +static inline unsigned long mas_get_safe_lower_bound(struct ma_state *mas, + unsigned char slot) +{ + if (!slot) + return mas->min; + + return mas_get_safe_pivot(mas, slot - 1) + 1; +} + static inline void ma_set_pivot(struct maple_node *mn, unsigned char slot, enum maple_type type, unsigned long val) { @@ -2997,11 +3007,7 @@ restart_prev_node: unsigned long last_pivot; unsigned long pivot = mas_get_safe_pivot(mas, slot); - if (slot) - min = mas_get_safe_pivot(mas, slot - 1) + 1; - else - min = mas->min; - + min = mas_get_safe_lower_bound(mas, slot); if (pivot < limit) goto no_entry; @@ -3163,8 +3169,7 @@ static inline bool mas_next_nentry(struct ma_state *mas, unsigned long max, unsigned char count = mt_slot_count(mas->node); void *entry; - if (slot) - r_start = mas_get_safe_pivot(mas, slot - 1) + 1; + r_start = mas_get_safe_lower_bound(mas, slot); while (slot < count) { pivot = mas_get_safe_pivot(mas, slot); @@ -3327,11 +3332,7 @@ static inline void* _mas_prev(struct ma_state *mas, unsigned long limit) mas->last = max; slot = mas_get_slot(mas); - if (slot) - mas->index = mas_get_safe_pivot(mas, slot - 1) + 1; - else - mas->index = mas->min; - + mas->index = mas_get_safe_lower_bound(mas, slot); return mas_get_rcu_slot(mas, mas_get_slot(mas)); } @@ -3364,14 +3365,6 @@ void *mas_prev(struct ma_state *mas, unsigned long min) } EXPORT_SYMBOL_GPL(mas_prev); -static inline unsigned long _mas_rev_awalk_min(struct ma_state *mas, - unsigned char slot, - enum maple_type type) -{ - if (!slot) - return mas->min; - return _mte_get_pivot(mas->node, slot - 1, type) + 1; -} static inline bool _mas_rev_awalk(struct ma_state *mas, unsigned long size) { enum maple_type type; @@ -3392,7 +3385,7 @@ static inline bool _mas_rev_awalk(struct ma_state *mas, unsigned long size) do { void *entry = NULL; - min = _mas_rev_awalk_min(mas, i, type); + min = mas_get_safe_lower_bound(mas, i); /* last is below this range */ if (mas->last < min) @@ -3435,8 +3428,7 @@ next_slot: default: do { - min = _mas_rev_awalk_min(mas, i, type); - + min = mas_get_safe_lower_bound(mas, i); /* last is too little for this range */ if (mas->last < min) goto next; @@ -3557,8 +3549,7 @@ next: default: pivot = 0; i = mas_get_slot(mas); - if (i) - min = _mas_get_safe_pivot(mas, i - 1, type) + 1; + min = mas_get_safe_lower_bound(mas, i); for (; i <= pivot_cnt; i++) { unsigned long this_gap; pivot = _mas_get_safe_pivot(mas, i, type); @@ -3832,9 +3823,7 @@ static int mas_fill_gap(struct ma_state *mas, void *entry, unsigned char slot, */ mas_ascend(mas); mas->max = mas_get_safe_pivot(mas, pslot); - if (pslot) - mas->min = mas_get_safe_pivot(mas, pslot - 1) + 1; - + mas->min = mas_get_safe_lower_bound(mas, pslot); mas->node = mn; mas_set_slot(mas, slot); _mas_store(mas, entry, false); -- 2.50.1