From: Liam R. Howlett Date: Thu, 7 Mar 2019 14:47:48 +0000 (-0500) Subject: maple: Fix off by one error when walking. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4dc3a35d3a5878377c881cc56067cf042029ed68;p=users%2Fjedix%2Flinux-maple.git maple: Fix off by one error when walking. When going to the next slot, the minimum value is actually pivot + 1 and not just the pivot value. Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index b2f7cbddf7e1..7229bc460be8 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -504,7 +504,7 @@ static inline void mas_update_limits(struct ma_state *ms, unsigned char slot, enum maple_type type) { if (slot > 0) - ms->min = _ma_get_pivot(ms->node, slot - 1, type); + ms->min = _ma_get_pivot(ms->node, slot - 1, type) + 1; if (slot < mt_slots[type] - 1) ms->max = _ma_get_pivot(ms->node, slot, type); @@ -1061,8 +1061,6 @@ static inline int _ma_insert(struct ma_state *mas, void *entry, /* Linear node type */ if (!pivot_cnt) { min = mas->index - mas->min; - if (mas->min) - min--; max = mas->last - mas->min; do ma_update_rcu_slot(mas->node, min++, entry); @@ -1079,13 +1077,13 @@ static inline int _ma_insert(struct ma_state *mas, void *entry, slot = o_end + 1; // Append. if (slot > 0) - min = ma_get_pivot(mas->node, slot - 1); + min = ma_get_pivot(mas->node, slot - 1) + 1; /* Figure out how many slots are needed for the entry. */ if (max != mas->last) n_end++; - if (mas->index && min != mas->index - 1) + if (mas->index && min != mas->index) n_end++; if (n_end > slot_cnt - 1 || @@ -1153,7 +1151,7 @@ static inline int _ma_insert(struct ma_state *mas, void *entry, - if (mas->index && min != mas->index - 1) { + if (mas->index && min != mas->index) { /* When writing a NULL entry, the order must be reversed to * ensure readers don't get incorrect data on appends */ @@ -1308,7 +1306,7 @@ static inline bool _mas_walk(struct ma_state *mas) max = pivot; break; } - min = pivot; + min = pivot + 1; } if ((i == pivot_cnt - 1) && (mas->index > pivot)) @@ -1321,8 +1319,6 @@ static inline bool _mas_walk(struct ma_state *mas) case maple_dense: // Linear node. i = mas->index - mas->min; - if (mas->min) - i--; goto done; break; }