From a713075774612043a93a9541bcad09ebef9fb93e Mon Sep 17 00:00:00 2001
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
Date: Sun, 6 Dec 2020 20:29:32 -0500
Subject: [PATCH] maple_tree: Move all searching to common debug area

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 lib/maple_tree.c | 183 ++++++++++++++++++++++++-----------------------
 1 file changed, 92 insertions(+), 91 deletions(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 1b8ea0f2d43b..80a29355bcd3 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -4711,66 +4711,6 @@ retry:
 	return entry;
 }
 
-static inline void mas_bfs_preorder(struct ma_state *mas)
-{
-
-	if (mas_is_start(mas)) {
-		mas_start(mas);
-		return;
-	}
-
-	if (mte_is_leaf(mas->node) && mte_is_root(mas->node)) {
-		mas->node = MAS_NONE;
-		return;
-	}
-
-}
-
-/* mas limits not adjusted */
-static inline void mas_dfs_preorder(struct ma_state *mas)
-{
-
-	struct maple_enode *prev;
-	unsigned char slot = 0;
-
-	if (mas_is_start(mas)) {
-		mas_start(mas);
-		return;
-	}
-
-	if (mte_is_leaf(mas->node) && mte_is_root(mas->node))
-		goto done;
-
-walk_up:
-	if (mte_is_leaf(mas->node) ||
-	    (slot >= mt_slot_count(mas->node))) {
-		if (mte_is_root(mas->node))
-			goto done;
-
-		slot = mte_parent_slot(mas->node) + 1;
-		mas->node = mt_mk_node(mte_parent(mas->node),
-				       mas_parent_enum(mas, mas->node));
-		goto walk_up;
-	}
-
-	prev = mas->node;
-	mas->node = mas_get_slot(mas, slot);
-	if (!mas->node) {
-		if (mte_is_root(prev))
-			goto done;
-
-		mas->node = prev;
-		slot = mte_parent_slot(mas->node) + 1;
-		mas->node = mt_mk_node(mte_parent(mas->node),
-				       mas_parent_enum(mas, mas->node));
-		goto walk_up;
-	}
-
-	return;
-done:
-	mas->node = MAS_NONE;
-}
-
 static inline unsigned char mas_dead_leaves(struct ma_state *mas, void **slots)
 {
 	struct maple_node *node;
@@ -5247,6 +5187,98 @@ unsigned long mt_get_alloc_size(void)
 #else // __KERNEL__ is defined.
 #define MA_PTR "%px"
 #endif
+/* mas limits not adjusted */
+static inline void mas_dfs_preorder(struct ma_state *mas)
+{
+
+	struct maple_enode *prev;
+	unsigned char slot = 0;
+
+	if (mas_is_start(mas)) {
+		mas_start(mas);
+		return;
+	}
+
+	if (mte_is_leaf(mas->node) && mte_is_root(mas->node))
+		goto done;
+
+walk_up:
+	if (mte_is_leaf(mas->node) ||
+	    (slot >= mt_slot_count(mas->node))) {
+		if (mte_is_root(mas->node))
+			goto done;
+
+		slot = mte_parent_slot(mas->node) + 1;
+		mas->node = mt_mk_node(mte_parent(mas->node),
+				       mas_parent_enum(mas, mas->node));
+		goto walk_up;
+	}
+
+	prev = mas->node;
+	mas->node = mas_get_slot(mas, slot);
+	if (!mas->node) {
+		if (mte_is_root(prev))
+			goto done;
+
+		mas->node = prev;
+		slot = mte_parent_slot(mas->node) + 1;
+		mas->node = mt_mk_node(mte_parent(mas->node),
+				       mas_parent_enum(mas, mas->node));
+		goto walk_up;
+	}
+
+	return;
+done:
+	mas->node = MAS_NONE;
+}
+
+
+static inline void mas_bfs_preorder(struct ma_state *mas)
+{
+
+	if (mas_is_start(mas)) {
+		mas_start(mas);
+		return;
+	}
+
+	if (mte_is_leaf(mas->node) && mte_is_root(mas->node)) {
+		mas->node = MAS_NONE;
+		return;
+	}
+
+}
+
+/* Depth first search, post-order */
+static inline void mas_dfs_postorder(struct ma_state *mas, unsigned long max)
+{
+
+	struct maple_enode *p = MAS_NONE, *mn = mas->node;
+	unsigned long p_min, p_max;
+
+	mas_next_node(mas, max);
+	if (!mas_is_none(mas))
+		return;
+
+	if (mte_is_root(mn))
+		return;
+
+	mas->node = mn;
+	mas_ascend(mas);
+	while (mas->node != MAS_NONE) {
+		p = mas->node;
+		p_min = mas->min;
+		p_max = mas->max;
+		mas_prev_node(mas, 0);
+	}
+
+	if (p == MAS_NONE)
+		return;
+
+	mas->node = p;
+	mas->max = p_max;
+	mas->min = p_min;
+}
+
 // Tree validations
 void mt_dump_node(void *entry, unsigned long min, unsigned long max,
 		unsigned int depth);
@@ -5609,37 +5641,6 @@ void mas_validate_limits(struct ma_state *mas)
 	}
 }
 
-/* Depth first search, post-order */
-static inline void mas_dfs_postorder(struct ma_state *mas, unsigned long max)
-{
-
-	struct maple_enode *p = MAS_NONE, *mn = mas->node;
-	unsigned long p_min, p_max;
-
-	mas_next_node(mas, max);
-	if (!mas_is_none(mas))
-		return;
-
-	if (mte_is_root(mn))
-		return;
-
-	mas->node = mn;
-	mas_ascend(mas);
-	while (mas->node != MAS_NONE) {
-		p = mas->node;
-		p_min = mas->min;
-		p_max = mas->max;
-		mas_prev_node(mas, 0);
-	}
-
-	if (p == MAS_NONE)
-		return;
-
-	mas->node = p;
-	mas->max = p_max;
-	mas->min = p_min;
-}
-
 void mt_validate_nulls(struct maple_tree *mt)
 {
 	void *entry, *last = (void *)1;
-- 
2.49.0