From: Liam R. Howlett Date: Wed, 23 Sep 2020 02:40:32 +0000 (-0400) Subject: maple_tree: mas_data_end starts at offset mt_min_slots now X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0fb845cef70373748e9ea7e1967003af10d87191;p=users%2Fjedix%2Flinux-maple.git maple_tree: mas_data_end starts at offset mt_min_slots now Signed-off-by: Liam R. Howlett --- 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;