summaryrefslogtreecommitdiff
path: root/lib/xarray.c
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2020-01-17 22:13:21 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-01-29 16:45:27 +0100
commitdd05cf12c72f11b7841d4ffeca29e5190606df1b (patch)
treebcfbb7292323391acf1e68eee3d8d4f8514bae83 /lib/xarray.c
parentdb38561288b75082b5e839decaa15ed253bd2298 (diff)
XArray: Fix xas_find returning too many entries
commit c44aa5e8ab58b5f4cf473970ec784c3333496a2e upstream. If you call xas_find() with the initial index > max, it should have returned NULL but was returning the entry at index. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/xarray.c')
-rw-r--r--lib/xarray.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/xarray.c b/lib/xarray.c
index 21b7e551bd4f..47e17d46e5f8 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* XArray implementation
- * Copyright (c) 2017 Microsoft Corporation
+ * Copyright (c) 2017-2018 Microsoft Corporation
+ * Copyright (c) 2018-2020 Oracle
* Author: Matthew Wilcox <willy@infradead.org>
*/
@@ -1081,6 +1082,8 @@ void *xas_find(struct xa_state *xas, unsigned long max)
if (xas_error(xas))
return NULL;
+ if (xas->xa_index > max)
+ return set_bounds(xas);
if (!xas->xa_node) {
xas->xa_index = 1;
@@ -1150,6 +1153,8 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark)
if (xas_error(xas))
return NULL;
+ if (xas->xa_index > max)
+ goto max;
if (!xas->xa_node) {
xas->xa_index = 1;
@@ -1867,7 +1872,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)
+
+ if (xas_invalid(&xas))
break;
if (xas_sibling(&xas))
continue;