]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Change _mas_prev/_mas_next return types
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 6 Jul 2021 17:57:45 +0000 (13:57 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 6 Jul 2021 18:04:48 +0000 (14:04 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index ab6bd9e53e133d254e426cee7eec3564cd26965a..50e32a7498c7dee5e00c7461ec29012c3d66fa4c 100644 (file)
@@ -2208,9 +2208,8 @@ bool mast_sibling_rebalance_right(struct maple_subtree_state *mast, bool free)
        return false;
 }
 
-static inline void mas_prev_node(struct ma_state *mas, unsigned long limit);
-static inline unsigned long mas_next_node(struct ma_state *mas,
-               unsigned long max);
+static inline int mas_prev_node(struct ma_state *mas, unsigned long min);
+static inline int mas_next_node(struct ma_state *mas, unsigned long max);
 /*
  * mast_cousin_rebalance_right() - Rebalance from nodes with different parents.
  * Check the right side, then the left.  Data is copied into the @mast->bn.
@@ -4131,12 +4130,12 @@ spanning_store:
  * mas_prev_node() - Find the prev non-null entry at the same level in the
  * tree.  The prev value will be mas->node[mas->offset] or MAS_NONE.
  * @mas: The maple state
- * @limit: The lower limit to search
+ * @min: The lower limit to search
  *
- * Result needs to be checked if the node is dead.
  * The prev node value will be mas->node[mas->offset] or MAS_NONE.
+ * Returns: 1 if the node is dead, 0 otherwise.
  */
-static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
+static inline int mas_prev_node(struct ma_state *mas, unsigned long min)
 {
        enum maple_type mt;
        int offset, level;
@@ -4145,7 +4144,7 @@ static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
        unsigned long *pivots;
 
        if (mas_is_none(mas))
-               return;
+               return 0;
 
        if (mte_is_root(mas->node))
                goto no_entry;
@@ -4159,7 +4158,7 @@ static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
                offset = mte_parent_slot(mas->node);
                mas_ascend(mas);
                if (unlikely(mte_dead_node(mas->node)))
-                       return;
+                       return 1;
 
                level++;
        } while (!offset);
@@ -4170,13 +4169,13 @@ static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
        slots = ma_slots(node, mt);
        pivots = ma_pivots(node, mt);
        mas->max = pivots[offset];
-       if (mas->max < limit)
+       if (mas->max < min)
                goto no_entry;
 
        while (level > 1) {
                mas->node = mas_slot(mas, slots, offset);
                if (unlikely(mte_dead_node(mas->node)))
-                       return;
+                       return 1;
 
                level--;
                mt = mte_node_type(mas->node);
@@ -4186,24 +4185,24 @@ static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
                offset = mas_data_end(mas);
                if (offset < mt_pivots[mt]) {
                        mas->max = pivots[offset];
-                       if (mas->max < limit)
+                       if (mas->max < min)
                                goto no_entry;
                }
        }
 
        mas->node = mas_slot(mas, slots, offset);
        if (unlikely(mte_dead_node(mas->node)))
-               return;
+               return 1;
 
        mas->offset = offset;
        if (offset)
                mas->min = pivots[offset - 1] + 1;
 
-       return;
+       return 0;
 
 no_entry:
        mas->node = MAS_NONE;
-       return;
+       return 0;
 
 }
 
@@ -4212,12 +4211,10 @@ no_entry:
  * @mas: The maple state
  * @max: The maximum pivot value to check.
  *
- * Return needs to be checked for dead nodes.
- *
- * Return: The next value will be mas->node[mas->offset] or MAS_NONE.
+ * The next value will be mas->node[mas->offset] or MAS_NONE.
+ * Return: 1 on dead node, 0 otherwise.
  */
-static inline unsigned long mas_next_node(struct ma_state *mas,
-               unsigned long max)
+static inline int mas_next_node(struct ma_state *mas, unsigned long max)
 {
        unsigned long min, pivot;
        unsigned long *pivots;
@@ -4244,7 +4241,7 @@ static inline unsigned long mas_next_node(struct ma_state *mas,
                        goto no_entry;
                mas_ascend(mas);
                if (unlikely(mte_dead_node(mas->node)))
-                       return mas->max;
+                       return 1;
 
                level++;
                end = mas_data_end(mas);
@@ -4259,7 +4256,7 @@ static inline unsigned long mas_next_node(struct ma_state *mas,
                /* Descend, if necessary */
                mas->node = mas_slot(mas, slots, offset);
                if (unlikely(mte_dead_node(mas->node)))
-                       return mas->max;
+                       return 1;
 
                level--;
                node = mas_mn(mas);
@@ -4272,15 +4269,15 @@ static inline unsigned long mas_next_node(struct ma_state *mas,
 
        mas->node = mas_slot(mas, slots, offset);
        if (unlikely(mte_dead_node(mas->node)))
-               return mas->max;
+               return 1;
 
        mas->min = min;
        mas->max = pivot;
-       return mas->max;
+       return 0;
 
 no_entry:
        mas->node = MAS_NONE;
-       return mas->max;
+       return 0;
 }
 
 /*
@@ -4567,10 +4564,10 @@ retry:
                if (unlikely((r_start > limit)))
                        break;
 
-               if (likely(entry)) {
-                       if (unlikely(mas_dead_node(mas, last)))
-                               goto retry;
+               if (unlikely(mas_dead_node(mas, last)))
+                       goto retry;
 
+               if (likely(entry)) {
                        mas->index = r_start;
                        return entry;
                }
@@ -4578,9 +4575,10 @@ retry:
 next_node:
                prev_node = mas->node;
                offset = mas->offset;
-               mas_next_node(mas, limit);
-               if (unlikely(mas_dead_node(mas, last)))
+               if (unlikely(mas_next_node(mas, limit))) {
+                       mas_dead_node(mas, last);
                        goto retry;
+               }
 
                mas->offset = 0;
                mt = mte_node_type(mas->node);
@@ -4610,9 +4608,10 @@ retry:
                if (likely(entry))
                        return entry;
 
-               mas_prev_node(mas, limit);
-               if (unlikely(mas_dead_node(mas, index)))
+               if (unlikely(mas_prev_node(mas, limit))) {
+                       mas_dead_node(mas, index);
                        goto retry;
+               }
 
                mas->offset = mt_slot_count(mas->node);
        }