]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple: Fix _mas_walk return & clean up ma_insert root expand logic
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 7 Mar 2019 15:18:29 +0000 (10:18 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 14:52:41 +0000 (10:52 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 7229bc460be8833789587858ab721a6db58ba39c..7a3970ea8cad948b407489732e170868ae06a721 100644 (file)
@@ -1281,8 +1281,9 @@ static inline bool _mas_walk(struct ma_state *mas)
 {
        enum maple_type type;
        struct maple_node *next;
-       unsigned long pivot_cnt, pivot, max, min, i;
-       bool ret = true;
+       unsigned long pivot = 0;
+       unsigned long pivot_cnt, max, min, i;
+       bool ret = false;
 
        mas->node = mas_start(mas);
        min = mas->min;
@@ -1294,12 +1295,11 @@ static inline bool _mas_walk(struct ma_state *mas)
 
                switch (type) {
                default:
-                       pivot = 0;
                        for (i = 0; i < pivot_cnt; i++) {
                                pivot = _ma_get_pivot(mas->node, i, type);
                                if (i != 0 && pivot == 0) {
-                                       ma_set_slot(mas, MAPLE_NODE_SLOTS);
-                                       return NULL;
+                                       i = MAPLE_NODE_SLOTS;
+                                       goto done;
                                }
 
                                if (mas->index <= pivot) {
@@ -1312,13 +1312,16 @@ static inline bool _mas_walk(struct ma_state *mas)
                        if ((i == pivot_cnt - 1) && (mas->index > pivot))
                                        i++;
 
-                       if (type < maple_range_16) // Leaf.
+                       if (type < maple_range_16) { // Leaf.
+                               ret = true;
                                goto done;
+                       }
                        break;
 
                case maple_dense:
                        // Linear node.
                        i = mas->index - mas->min;
+                       ret = true;
                        goto done;
                        break;
                }
@@ -1344,18 +1347,19 @@ static inline void ma_insert(struct ma_state *mas, void *entry)
 
        mas->node = mas_start(mas);
        if (!xa_is_node(rcu_dereference(mas->tree->ma_root))) {
-               if (mas->last == 0) {
-                       if (mas->node != NULL)
-                               goto exists;
-
-                       if (((unsigned long) (entry) & 3) == 2)
-                               ma_root_expand(mas, entry);
-                       else
-                               rcu_assign_pointer(mas->tree->ma_root, entry);
-
+               if (mas->last != 0) {
+                       ma_root_expand(mas, entry);
                        return;
                }
-               ma_root_expand(mas, entry);
+
+               if (mas->node != NULL)
+                       goto exists;
+
+               if (((unsigned long) (entry) & 3) == 2)
+                       ma_root_expand(mas, entry);
+               else
+                       rcu_assign_pointer(mas->tree->ma_root, entry);
+
                return;
        }