]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple: Fix off by one error when walking.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 7 Mar 2019 14:47:48 +0000 (09:47 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 14:52:41 +0000 (10:52 -0400)
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 <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index b2f7cbddf7e183f9cc21d8d84689f1944fc66a73..7229bc460be8833789587858ab721a6db58ba39c 100644 (file)
@@ -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;
                }