]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix mas_awalk gap issues
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 13 Aug 2020 16:29:42 +0000 (12:29 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:09:11 +0000 (15:09 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 06807be04e563b956c86d1dca0bc89d9f384e037..22a60dcfe0e94afa9f6cd2070ad1a9262fe8a914 100644 (file)
@@ -3621,7 +3621,7 @@ ascend:
 static inline bool _mas_awalk(struct ma_state *mas, unsigned long size)
 {
        enum maple_type type = mte_node_type(mas->node);
-       unsigned long pivot, min, gap;
+       unsigned long pivot, min, gap = 0;
        unsigned char slot = 0, pivot_cnt = mt_pivots[type];
        bool found = false;
 
@@ -3641,23 +3641,15 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size)
                                goto next_slot;
 
                        if (ma_is_leaf(type)) {
-                               if (!mt_is_empty(mas_get_rcu_slot(mas, slot)))
-                                       goto next_slot;
-
-                               gap = pivot - mas->index;
-                               if (!gap) // No entry, pivot = index.
-                                       gap = 1;
-
-                               if (mas->last + size < pivot - gap) { // upper bound
-                                       mas_set_err(mas, -EBUSY);
-                                       return true;
-                               }
-                               if (mas->last < pivot - gap) // gap check
-                                       break;
+                               gap = 0;
+                               if (mt_is_empty(mas_get_rcu_slot(mas, slot)))
+                                       gap = min(pivot, mas->last) -
+                                               max(mas->index, min) + 1;
                        } else {
                                gap = mte_get_gap(mas->node, slot);
                        }
 
+next_slot:
                        if (gap >= size) {
                                if (ma_is_leaf(type)) {
                                        found = true;
@@ -3670,7 +3662,6 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size)
                                        break;
                                }
                        }
-next_slot:
                        min = pivot + 1;
                        if (mas->last < min) {
                                mas_set_err(mas, -EBUSY);