radix-tree: fix contiguous iterator
Subsystems (2)
PATCH 1/1 radix-tree: fix contiguous iterator
This patch fixes bug in macro radix_tree_for_each_contig().
If radix_tree_next_slot() sees NULL in next slot it returns NULL, but following radix_tree_next_chunk() switches iterating into next chunk. As result iterating becomes non-contiguous and breaks vfs "splice" and all its users.
Signed-off-by Konstantin Khlebnikov <[email protected]>
Reported-and-bisected-by Hans de Bruin <[email protected]>
Reported-and-bisected-by Ondrej Zary <[email protected]>
Reported-and-bisected-by Toralf Förster <[email protected]>
Cc stable <[email protected]> # 3.4.x
--- include/linux/radix-tree.h | 5 ++++- lib/radix-tree.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/radix-tree.h +4 -1
@@ -368,8 +368,11 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags) iter->index++;if (likely (*slot))return slot; -if (flags &RADIX_TREE_ITER_CONTIG ) +if (flags &RADIX_TREE_ITER_CONTIG ) { +/* forbid switching to the next chunk */ + iter->next_index =0 ;break ; + } } }return NULL ;
lib/radix-tree.c +3 -0
@@ -673,6 +673,9 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,* during iterating; it can be zero only at the beginning. * And we cannot overflow iter->next_index in a single step, * because RADIX_TREE_MAP_SHIFT < BITS_PER_LONG. +* +* This condition also used by radix_tree_next_slot() to stop +* contiguous iterating, and forbid swithing to the next chunk. */ index = iter->next_index;if (!index && iter->index)