From a1006080b184c699e3cae8cc91519244c67e191d Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 22 Sep 2020 22:40:32 -0400 Subject: [PATCH] maple_tree: mas_data_end starts at offset mt_min_slots now Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ec1f782d2a68..66c539b4c815 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1024,15 +1024,23 @@ done: */ static inline unsigned char mas_data_end(const struct ma_state *mas) { - unsigned char offset = 0; enum maple_type type = mte_node_type(mas->node); + unsigned char offset = mt_min_slots[type]; unsigned long piv, *pivots = ma_pivots(mas_mn(mas), type); - while (offset < mt_slots[type]) { - piv = _mas_safe_pivot(mas, pivots, offset, type); - if ((!piv && offset) || piv >= mas->max) - break; - offset++; + if (pivots[offset]) { + while (offset < mt_slots[type]) { + piv = _mas_safe_pivot(mas, pivots, offset, type); + if ((!piv && offset) || piv >= mas->max) + break; + offset++; + } + } else { + offset--; + do { + if (pivots[offset]) + break; + } while (--offset); } return offset; -- 2.50.1