From: Liam R. Howlett Date: Tue, 16 Sep 2025 19:00:45 +0000 (-0400) Subject: Correctly set src max on node_cp X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=77d1a6dd8acd8b570243e2759cef47cefb8466de;p=users%2Fjedix%2Flinux-maple.git Correctly set src max on node_cp Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3a75f5db9843..a7e121109ba3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3008,11 +3008,21 @@ void node_finalise(struct maple_node *node, enum maple_type mt, unsigned char en static inline void append_node_cp(struct maple_copy *cp, struct ma_state *mas, unsigned char start, unsigned char end) { - unsigned char count = cp->s_count; + struct maple_node *node; + enum maple_type mt; + unsigned char count; + + count = cp->s_count; + node = mas_mn(mas); + mt = mte_node_type(mas->node); + + cp->src[count].node = node; + cp->src[count].mt = mt; + if (mas->end <= end) + cp->src[count].max = mas->max; + else + cp->src[count].max = ma_pivots(node, mt)[end]; - cp->src[count].node = mas_mn(mas); - cp->src[count].mt = mte_node_type(mas->node); - cp->src[count].max = mas->max; cp->src[count].start = start; cp->src[count].end = end; cp->s_count++; @@ -3139,7 +3149,7 @@ void multi_dst_setup(struct maple_copy *cp, struct ma_state *mas, * Leaf nodes are a bit tricky because we cannot assume the data * can fit due to the NULL limitation on node ends. */ - off = cp->split;; + off = cp->split; for (s = 0; s < cp->s_count; s++) { unsigned char s_off; @@ -3222,7 +3232,7 @@ void cp_data_write(struct maple_copy *cp, struct ma_state *mas) unsigned char data, data_offset; unsigned char src_end, s_offset; unsigned char split, next_node, size; - unsigned long s_max; + unsigned long s_max, d_max; enum maple_type s_mt, d_mt; s = d = 0; @@ -3254,20 +3264,21 @@ void cp_data_write(struct maple_copy *cp, struct ma_state *mas) if (split - dst_offset + 1 < size) size = split - dst_offset + 1; - node_copy(mas, src, s_offset, size, s_max, s_mt, dst, - dst_offset, d_mt); + d_max = node_copy(mas, src, s_offset, size, s_max, s_mt, + dst, dst_offset, d_mt); data_offset += size; dst_offset += size; s_offset += size; if (s_offset > src_end) { /* This source is exhausted */ - cp->dst[d].max = s_max; s++; if (s >= cp->s_count) { + cp->dst[d].max = d_max; node_finalise(dst, d_mt, dst_offset); return; } + d_max = s_max; /* Reset local src */ src = cp->src[s].node; s_offset = cp->src[s].start; @@ -3282,12 +3293,7 @@ void cp_data_write(struct maple_copy *cp, struct ma_state *mas) next_node = data + 1; split = cp->split; - if (dst_offset <= mt_pivots[d_mt]) { - cp->dst[d].max = ma_pivots(dst, d_mt)[dst_offset - 1]; - } else { - cp->dst[d].max = ma_pivots(src, s_mt)[s_offset - 1]; - } - + cp->dst[d].max = d_max; /* Handle null entries */ if (cp->dst[d].max != ULONG_MAX && !ma_slots(dst, d_mt)[dst_offset - 1]) {