]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Clean up dead node checks.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 6 Jul 2021 16:44:31 +0000 (12:44 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 6 Jul 2021 18:16:46 +0000 (14:16 -0400)
Depend on _mas_walk() on looping on existing nodes.
remove duplicate code in mas_range_load and mas_walk.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index cc70ef6c606e03472aa363285e2e4d144f2592b0..d870344c25389a2f1921e611592c47f67e16cf41 100644 (file)
@@ -4779,6 +4779,38 @@ done:
        return found;
 }
 
+/*
+ * mas_range_load() - Load the entry at an index and get the range.
+ * @mas: The maple state
+ * @*range_min: Pointer to store the minimum range the entry is valid
+ * @*range_max: Pointer to store the maximum range the entry is valid
+ *
+ * Must hold rcu_read_lock or the write lock.
+ * Find where mas->index is located and return the entry.
+ * @mas->node will point to the node containing the entry.
+ * range_min and range_max will be set accordingly.
+ *
+ * Return: The entry at mas->index or %NULL
+ */
+static inline void *mas_range_load(struct ma_state *mas,
+          unsigned long *range_min, unsigned long *range_max)
+{
+       void *entry = NULL;
+
+       if (mas_is_none(mas) || mas_is_paused(mas))
+               mas->node = MAS_START;
+
+       /* dead nodes handled by _mas_walk */
+       if (_mas_walk(mas, range_min, range_max))
+               if (unlikely(mas->node == MAS_ROOT))
+                       return mas_root(mas);
+
+       if (likely(mas->offset != MAPLE_NODE_SLOTS))
+               entry = mas_get_slot(mas, mas->offset);
+
+       return entry;
+}
+
 /**
  * mas_walk() - Search for @mas->index in the tree.
  * @mas - the maple state.
@@ -4791,24 +4823,12 @@ done:
 void *mas_walk(struct ma_state *mas)
 {
        unsigned long range_min, range_max;
-       unsigned long index = mas->index;
        void *entry;
 
-       if (mas_is_none(mas) || mas_is_paused(mas))
-               mas->node = MAS_START;
-
-       _mas_walk(mas, &range_min, &range_max);
-retry:
-       entry = NULL;
-       if (mas->offset != MAPLE_NODE_SLOTS)
-               entry = mas_get_slot(mas, mas->offset);
-
-       if (unlikely(mas_dead_node(mas, index)))
-               goto retry;
-
+       /* Retries on dead nodes handled by mas_range_load */
+       entry = mas_range_load(mas, &range_min, &range_max);
        mas->index = range_min;
        mas->last = range_max;
-
        return entry;
 }
 
@@ -5172,42 +5192,6 @@ no_gap:
        return -EBUSY;
 }
 
-/*
- * mas_range_load() - Load the entry at an index and get the range.
- * @mas: The maple state
- * @*range_min: Pointer to store the minimum range the entry is valid
- * @*range_max: Pointer to store the maximum range the entry is valid
- *
- * Must hold rcu_read_lock or the write lock.
- * Find where mas->index is located and return the entry.
- * @mas->node will point to the node containing the entry.
- * range_min and range_max will be set accordingly.
- *
- * Return: The entry at mas->index or %NULL
- */
-static inline void *mas_range_load(struct ma_state *mas,
-          unsigned long *range_min, unsigned long *range_max)
-{
-       unsigned long index = mas->index;
-       void *entry;
-
-       if (mas_is_none(mas) || mas_is_paused(mas))
-               mas->node = MAS_START;
-
-       if (_mas_walk(mas, range_min, range_max))
-               if (unlikely(mas->node == MAS_ROOT))
-                       return mas_root(mas);
-retry:
-       entry = NULL;
-       if (likely(mas->offset != MAPLE_NODE_SLOTS))
-               entry = mas_get_slot(mas, mas->offset);
-
-       if (unlikely(mas_dead_node(mas, index)))
-               goto retry;
-
-       return entry;
-}
-
 /*
  * _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.
@@ -5219,16 +5203,10 @@ retry:
 static void *_mas_find(struct ma_state *mas, unsigned long limit)
 {
        if (unlikely(mas_is_start(mas))) {
-               /* First run */
-               void *entry = NULL;
-               unsigned long range_max;
-               unsigned long range_start;
+               /* First run or continue */
+               void *entry;
 
-               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;
+               entry = mas_walk(mas);
                if (entry)
                        return entry;
        }
@@ -5591,9 +5569,13 @@ void *mas_next(struct ma_state *mas, unsigned long max)
                return NULL;
 
        if (mas_is_start(mas)) {
+               void *entry;
+
                mas->index = ++mas->last;
-               /* Retries on dead nodes handled by _mas_find */
-               return _mas_find(mas, max);
+               /* Retries on dead nodes handled by mas_walk */
+               entry = mas_walk(mas);
+               if (entry)
+                       return entry;
        }
 
        /* Retries on dead nodes handled by _mas_next */