summaryrefslogtreecommitdiff
path: root/lib/xarray.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-11-01 16:55:19 -0400
committerMatthew Wilcox <willy@infradead.org>2018-11-05 14:56:46 -0500
commit8229706e03e4147f3e22d1de0d30630cde6d18a9 (patch)
tree1994f5ff08f7b5c459eba5e26c868ee182d2392a /lib/xarray.c
parent651022382c7f8da46cb4872a545ee1da6d097d2a (diff)
downloadlwn-8229706e03e4147f3e22d1de0d30630cde6d18a9.tar.gz
lwn-8229706e03e4147f3e22d1de0d30630cde6d18a9.zip
XArray: Fix xa_for_each with a single element at 0
The following sequence of calls would result in an infinite loop in xa_find_after(): xa_store(xa, 0, x, GFP_KERNEL); index = 0; xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { } xa_find_after() was confusing the situation where we found no entry in the tree with finding a multiorder entry, so it would look for the successor entry forever. Just check for this case explicitly. Includes a few new checks in the test suite to be sure this doesn't reappear. Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/xarray.c')
-rw-r--r--lib/xarray.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/xarray.c b/lib/xarray.c
index 8b176f009c08..c991ff4523ef 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -1829,6 +1829,8 @@ void *xa_find_after(struct xarray *xa, unsigned long *indexp,
entry = xas_find_marked(&xas, max, filter);
else
entry = xas_find(&xas, max);
+ if (xas.xa_node == XAS_BOUNDS)
+ break;
if (xas.xa_shift) {
if (xas.xa_index & ((1UL << xas.xa_shift) - 1))
continue;