aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_xarray.c
diff options
context:
space:
mode:
authorPrzemek Kitszel <[email protected]>2025-03-20 10:22:19 +0000
committerAndrew Morton <[email protected]>2025-05-12 00:48:19 +0000
commit4c97a17a252bf8396f7bd65efced00bf401a8c25 (patch)
treebfdfe7beb540ce8a243ac2e3d7d5a61f924c1f27 /lib/test_xarray.c
parentarm64/mm: define ptdesc_t (diff)
downloadkernel-4c97a17a252bf8396f7bd65efced00bf401a8c25.tar.gz
kernel-4c97a17a252bf8396f7bd65efced00bf401a8c25.zip
xarray: make xa_alloc_cyclic() return 0 on all success cases
Change xa_alloc_cyclic() to return 0 even on wrap-around. Do the same for xa_alloc_cyclic_irq() and xa_alloc_cyclic_bh(). This will prevent any future bug of treating return of 1 as an error: int ret = xa_alloc_cyclic(...) if (ret) // currently mishandles ret==1 goto failure; If there will be someone interested in when wrap-around occurs, there is still __xa_alloc_cyclic() that behaves as before. For now there is no such user. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Przemek Kitszel <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Link: https://lore.kernel.org/netdev/[email protected] Cc: Andriy Shevchenko <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Michal Swiatkowski <[email protected]> Cc: Przemek Kitszel <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r--lib/test_xarray.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index 080a39d22e73..5ca0aefee9aa 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -1040,6 +1040,7 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)
unsigned int i, id;
unsigned long index;
void *entry;
+ int ret;
XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(1), limit,
&next, GFP_KERNEL) != 0);
@@ -1059,7 +1060,7 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)
else
entry = xa_mk_index(i - 0x3fff);
XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, entry, limit,
- &next, GFP_KERNEL) != (id == 1));
+ &next, GFP_KERNEL) != 0);
XA_BUG_ON(xa, xa_mk_index(id) != entry);
}
@@ -1072,7 +1073,7 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)
xa_limit_32b, &next, GFP_KERNEL) != 0);
XA_BUG_ON(xa, id != UINT_MAX);
XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base),
- xa_limit_32b, &next, GFP_KERNEL) != 1);
+ xa_limit_32b, &next, GFP_KERNEL) != 0);
XA_BUG_ON(xa, id != base);
XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base + 1),
xa_limit_32b, &next, GFP_KERNEL) != 0);
@@ -1080,7 +1081,19 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)
xa_for_each(xa, index, entry)
xa_erase_index(xa, index);
+ XA_BUG_ON(xa, !xa_empty(xa));
+ /* check wrap-around return of __xa_alloc_cyclic() */
+ next = UINT_MAX;
+ XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX),
+ xa_limit_32b, &next, GFP_KERNEL) != 0);
+ xa_lock(xa);
+ ret = __xa_alloc_cyclic(xa, &id, xa_mk_index(base), xa_limit_32b,
+ &next, GFP_KERNEL);
+ xa_unlock(xa);
+ XA_BUG_ON(xa, ret != 1);
+ xa_for_each(xa, index, entry)
+ xa_erase_index(xa, index);
XA_BUG_ON(xa, !xa_empty(xa));
}