From: Liam R. Howlett Date: Wed, 2 Mar 2022 18:51:22 +0000 (-0500) Subject: maple_tree: Fix node_size check for slow path goto in mas_wr_modify() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=10c99eabd4c2d04283f914be02c227b8b09ac5c6;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix node_size check for slow path goto in mas_wr_modify() Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 12e4787c4d83..cf7d415441ca 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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) &&