]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix _mas_store() expand null
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 29 Oct 2020 19:11:39 +0000 (15:11 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:13:50 +0000 (15:13 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index ce4c0d15deb75272f6e5bafd44f5da32e5bb34ae..b58d84fd213436c43c1fa9db7ed26806bad60b41 100644 (file)
@@ -3315,29 +3315,33 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite
                                mas->last = r_max;
                        // if this one is null the next and prev are not.
                } else {
-                       // Check prev slot if we are overwriting the start.
-                       if (mas->index == r_min && mas->offset &&
-                           !slots[mas->offset - 1]) {
-                               mas->offset--;
-                               r_min = mas->index = mas_safe_min(mas, pivots,
-                                                                 mas->offset);
-                               r_max = pivots[mas->offset];
-                       }
-
                        // Check next slot if we are overwriting the end.
-                       if (mas->last == r_max && !slots[mas->offset + 1]) {
-                               mas->last = pivots[mas->offset + 1];
-                       }
-                       else if (mas->last > r_max) { // expand over this slot if necessary.
+                       if ((mas->last == r_max) && !slots[mas->offset + 1]) {
+                               if (mas->offset < mt_pivots[mt] - 1 &&
+                                   pivots[mas->offset + 1])
+                                       mas->last = pivots[mas->offset + 1];
+                               else
+                                       mas->last = mas->max;
+                       } else if (mas->last > r_max) { // expand over this slot if necessary.
                                unsigned long piv;
+
                                do {
                                        piv = _mas_safe_pivot(mas, pivots,
                                                              ++offset_end, mt);
-                               } while (mas->last > piv);
+                               } while (mas->last >= piv);
 
                                if (!slots[offset_end])
                                        mas->last = piv;
                        }
+
+                       // Check prev slot if we are overwriting the start.
+                       if (mas->index == r_min && mas->offset &&
+                           !slots[mas->offset - 1]) {
+                               mas->offset--;
+                               r_min = mas->index = mas_safe_min(mas, pivots,
+                                                                 mas->offset);
+                               r_max = pivots[mas->offset];
+                       }
                }
        }