Skip to content

Commit 06e8fd9

Browse files
howlettakpm00
authored andcommitted
maple_tree: fix mas_empty_area() search
The internal function of mas_awalk() was incorrectly skipping the last entry in a node, which could potentially be NULL. This is only a problem for the left-most node in the tree - otherwise that NULL would not exist. Fix mas_awalk() by using the metadata to obtain the end of the node for the loop and the logical pivot as apposed to the raw pivot value. Link: https://lkml.kernel.org/r/[email protected] Fixes: 54a611b ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett <[email protected]> Reported-by: Rick Edgecombe <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fad8e42 commit 06e8fd9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/maple_tree.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,24 +5056,26 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size)
50565056
{
50575057
enum maple_type type = mte_node_type(mas->node);
50585058
unsigned long pivot, min, gap = 0;
5059-
unsigned char offset;
5060-
unsigned long *gaps;
5061-
unsigned long *pivots = ma_pivots(mas_mn(mas), type);
5062-
void __rcu **slots = ma_slots(mas_mn(mas), type);
5059+
unsigned char offset, data_end;
5060+
unsigned long *gaps, *pivots;
5061+
void __rcu **slots;
5062+
struct maple_node *node;
50635063
bool found = false;
50645064

50655065
if (ma_is_dense(type)) {
50665066
mas->offset = (unsigned char)(mas->index - mas->min);
50675067
return true;
50685068
}
50695069

5070-
gaps = ma_gaps(mte_to_node(mas->node), type);
5070+
node = mas_mn(mas);
5071+
pivots = ma_pivots(node, type);
5072+
slots = ma_slots(node, type);
5073+
gaps = ma_gaps(node, type);
50715074
offset = mas->offset;
50725075
min = mas_safe_min(mas, pivots, offset);
5073-
for (; offset < mt_slots[type]; offset++) {
5074-
pivot = mas_safe_pivot(mas, pivots, offset, type);
5075-
if (offset && !pivot)
5076-
break;
5076+
data_end = ma_data_end(node, type, pivots, mas->max);
5077+
for (; offset <= data_end; offset++) {
5078+
pivot = mas_logical_pivot(mas, pivots, offset, type);
50775079

50785080
/* Not within lower bounds */
50795081
if (mas->index > pivot)

0 commit comments

Comments
 (0)