]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix node_size check for slow path goto in mas_wr_modify()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 2 Mar 2022 18:51:22 +0000 (13:51 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 8 Mar 2022 18:19:16 +0000 (13:19 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 12e4787c4d8361ea0e05687d05c6c09afb6444e7..cf7d415441ca72880ddc6d822b86c6a97f434ae6 100644 (file)
@@ -1971,7 +1971,8 @@ static inline void mab_mas_cp(struct maple_big_node *b_node,
                if (pivots[end] != mas->max)
                        end++;
 
-               ma_set_meta(node, mt, 0, end);
+               if (end < mt_slots[mt] - 1)
+                       ma_set_meta(node, mt, 0, end);
        }
 }
 
@@ -3490,8 +3491,6 @@ static inline int mas_commit_b_node(struct ma_state *mas,
        node->parent = mas_mn(mas)->parent;
        mas->node = mt_mk_node(node, b_type);
        mab_mas_cp(b_node, 0, b_end, mas, true);
-       if (b_end < mt_pivots[b_type] - 1)
-               ma_set_meta(node, b_type, 0, b_end);
 
        mas_replace(mas, false);
 reuse_node:
@@ -4185,6 +4184,7 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas)
 {
        unsigned char zero;
        unsigned char node_slots;
+       unsigned char node_size;
        struct ma_state *mas = wr_mas->mas;
        struct maple_big_node b_node;
 
@@ -4198,8 +4198,12 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas)
 
        /* Attempt to append */
        node_slots = mt_slots[wr_mas->type];
+       node_size = wr_mas->node_end - wr_mas->offset_end + mas->offset + 2;
+       if (mas->max == ULONG_MAX)
+               node_size++;
+
        /* slot and node store will not fit, go to the slow path */
-       if (unlikely(wr_mas->offset_end + 1 >= node_slots))
+       if (unlikely(node_size >= node_slots))
                goto slow_path;
 
        if (wr_mas->entry && (wr_mas->node_end < node_slots - 1) &&