aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
1355 xa_destroy(xa); 1355 xa_destroy(xa);
1356} 1356}
1357 1357
1358/*
1359 * We should always be able to store without allocating memory after
1360 * reserving a slot.
1361 */
1358static void check_align_2(struct xarray *xa, char *name) 1362static void check_align_2(struct xarray *xa, char *name)
1359{ 1363{
1360 int i; 1364 int i;
@@ -1366,6 +1370,12 @@ static void check_align_2(struct xarray *xa, char *name)
1366 xa_erase(xa, 0); 1370 xa_erase(xa, 0);
1367 } 1371 }
1368 1372
1373 for (i = 0; i < 8; i++) {
1374 XA_BUG_ON(xa, xa_reserve(xa, 0, GFP_KERNEL) != 0);
1375 XA_BUG_ON(xa, xa_store(xa, 0, name + i, 0) != NULL);
1376 xa_erase(xa, 0);
1377 }
1378
1369 XA_BUG_ON(xa, !xa_empty(xa)); 1379 XA_BUG_ON(xa, !xa_empty(xa));
1370} 1380}
1371 1381
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)
767 void *first, *next; 767 void *first, *next;
768 bool value = xa_is_value(entry); 768 bool value = xa_is_value(entry);
769 769
770 if (entry) 770 if (entry) {
771 first = xas_create(xas, !xa_is_node(entry)); 771 bool allow_root = !xa_is_node(entry) && !xa_is_zero(entry);
772 else 772 first = xas_create(xas, allow_root);
773 } else {
773 first = xas_load(xas); 774 first = xas_load(xas);
775 }
774 776
775 if (xas_invalid(xas)) 777 if (xas_invalid(xas))
776 return first; 778 return first;