Commit 06e8fd99 authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton

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/20230414145728.4067069-2-Liam.Howlett@oracle.com
Fixes: 54a611b6 ("Maple Tree: add new data structure")
Signed-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: default avatarRick Edgecombe <rick.p.edgecombe@intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent fad8e429
...@@ -5056,10 +5056,10 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size) ...@@ -5056,10 +5056,10 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size)
{ {
enum maple_type type = mte_node_type(mas->node); enum maple_type type = mte_node_type(mas->node);
unsigned long pivot, min, gap = 0; unsigned long pivot, min, gap = 0;
unsigned char offset; unsigned char offset, data_end;
unsigned long *gaps; unsigned long *gaps, *pivots;
unsigned long *pivots = ma_pivots(mas_mn(mas), type); void __rcu **slots;
void __rcu **slots = ma_slots(mas_mn(mas), type); struct maple_node *node;
bool found = false; bool found = false;
if (ma_is_dense(type)) { if (ma_is_dense(type)) {
...@@ -5067,13 +5067,15 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size) ...@@ -5067,13 +5067,15 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size)
return true; return true;
} }
gaps = ma_gaps(mte_to_node(mas->node), type); node = mas_mn(mas);
pivots = ma_pivots(node, type);
slots = ma_slots(node, type);
gaps = ma_gaps(node, type);
offset = mas->offset; offset = mas->offset;
min = mas_safe_min(mas, pivots, offset); min = mas_safe_min(mas, pivots, offset);
for (; offset < mt_slots[type]; offset++) { data_end = ma_data_end(node, type, pivots, mas->max);
pivot = mas_safe_pivot(mas, pivots, offset, type); for (; offset <= data_end; offset++) {
if (offset && !pivot) pivot = mas_logical_pivot(mas, pivots, offset, type);
break;
/* Not within lower bounds */ /* Not within lower bounds */
if (mas->index > pivot) if (mas->index > pivot)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment