summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2019-02-21 17:54:44 -0500
committerMatthew Wilcox <willy@infradead.org>2019-02-21 17:54:44 -0500
commit4a5c8d898948d1ac876522cdd62f07a78104bfe9 (patch)
treef7b60e242dc970b9f4c6524f6882a4eb9261c388 /lib
parent2fbe967b3eb7466f679307b38564b8271c093241 (diff)
downloadlinux-4a5c8d898948d1ac876522cdd62f07a78104bfe9.tar.gz
linux-4a5c8d898948d1ac876522cdd62f07a78104bfe9.tar.bz2
linux-4a5c8d898948d1ac876522cdd62f07a78104bfe9.zip
XArray: Fix xa_reserve for 2-byte aligned entries
If we reserve index 0, the next entry to be stored there might be 2-byte aligned. That means we have to create the root xa_node at the time of reserving the initial entry. Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_xarray.c10
-rw-r--r--lib/xarray.c8
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index bc202d468a6b..5d4bad8bd96a 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -1355,6 +1355,10 @@ static void check_align_1(struct xarray *xa, char *name)
xa_destroy(xa);
}
+/*
+ * We should always be able to store without allocating memory after
+ * reserving a slot.
+ */
static void check_align_2(struct xarray *xa, char *name)
{
int i;
@@ -1366,6 +1370,12 @@ static void check_align_2(struct xarray *xa, char *name)
xa_erase(xa, 0);
}
+ for (i = 0; i < 8; i++) {
+ XA_BUG_ON(xa, xa_reserve(xa, 0, GFP_KERNEL) != 0);
+ XA_BUG_ON(xa, xa_store(xa, 0, name + i, 0) != NULL);
+ xa_erase(xa, 0);
+ }
+
XA_BUG_ON(xa, !xa_empty(xa));
}
diff --git a/lib/xarray.c b/lib/xarray.c
index 2cc3798672f7..6be3acbb861f 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -767,10 +767,12 @@ void *xas_store(struct xa_state *xas, void *entry)
void *first, *next;
bool value = xa_is_value(entry);
- if (entry)
- first = xas_create(xas, !xa_is_node(entry));
- else
+ if (entry) {
+ bool allow_root = !xa_is_node(entry) && !xa_is_zero(entry);
+ first = xas_create(xas, allow_root);
+ } else {
first = xas_load(xas);
+ }
if (xas_invalid(xas))
return first;