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.
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;
}
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.
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;
}
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 */