aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_xarray.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-12-13 13:57:42 -0500
committerMatthew Wilcox <willy@infradead.org>2018-12-13 14:07:33 -0500
commit48483614de97c4f5219abeda630e62b2bebdce62 (patch)
treeefd9c5d74cf60cdd6ff5c5f618f74e6fffed0493 /lib/test_xarray.c
parent4f145cd66a1a76136ff5a03a99e37ba082715dc6 (diff)
XArray: Fix xa_alloc when id exceeds max
Specifying a starting ID greater than the maximum ID isn't something attempted very often, but it should fail. It was succeeding due to xas_find_marked() returning the wrong error state, so add tests for both xa_alloc() and xas_find_marked(). Fixes: b803b42823d0 ("xarray: Add XArray iterators") Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r--lib/test_xarray.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index 6f09c845187e..4676c0a1eeca 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -633,6 +633,15 @@ static noinline void check_xa_alloc(void)
633 GFP_KERNEL) != -ENOSPC); 633 GFP_KERNEL) != -ENOSPC);
634 XA_BUG_ON(&xa0, id != 0xffffffffU); 634 XA_BUG_ON(&xa0, id != 0xffffffffU);
635 xa_destroy(&xa0); 635 xa_destroy(&xa0);
636
637 id = 10;
638 XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, 5, xa_mk_index(id),
639 GFP_KERNEL) != -ENOSPC);
640 XA_BUG_ON(&xa0, xa_store_index(&xa0, 3, GFP_KERNEL) != 0);
641 XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, 5, xa_mk_index(id),
642 GFP_KERNEL) != -ENOSPC);
643 xa_erase_index(&xa0, 3);
644 XA_BUG_ON(&xa0, !xa_empty(&xa0));
636} 645}
637 646
638static noinline void __check_store_iter(struct xarray *xa, unsigned long start, 647static noinline void __check_store_iter(struct xarray *xa, unsigned long start,
@@ -822,10 +831,34 @@ static noinline void check_find_2(struct xarray *xa)
822 xa_destroy(xa); 831 xa_destroy(xa);
823} 832}
824 833
834static noinline void check_find_3(struct xarray *xa)
835{
836 XA_STATE(xas, xa, 0);
837 unsigned long i, j, k;
838 void *entry;
839
840 for (i = 0; i < 100; i++) {
841 for (j = 0; j < 100; j++) {
842 for (k = 0; k < 100; k++) {
843 xas_set(&xas, j);
844 xas_for_each_marked(&xas, entry, k, XA_MARK_0)
845 ;
846 if (j > k)
847 XA_BUG_ON(xa,
848 xas.xa_node != XAS_RESTART);
849 }
850 }
851 xa_store_index(xa, i, GFP_KERNEL);
852 xa_set_mark(xa, i, XA_MARK_0);
853 }
854 xa_destroy(xa);
855}
856
825static noinline void check_find(struct xarray *xa) 857static noinline void check_find(struct xarray *xa)
826{ 858{
827 check_find_1(xa); 859 check_find_1(xa);
828 check_find_2(xa); 860 check_find_2(xa);
861 check_find_3(xa);
829 check_multi_find(xa); 862 check_multi_find(xa);
830 check_multi_find_2(xa); 863 check_multi_find_2(xa);
831} 864}