aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_xarray.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-12-17 14:45:36 -0500
committerMatthew Wilcox <willy@infradead.org>2019-01-06 21:24:43 -0500
commit4a31896c5b5a2715ecf4033426aa0a35066d92d6 (patch)
treeea33358cfa40d96ce92fb8605c7a8639f00cac5f /lib/test_xarray.c
parent02669b17a433c242a40f01f14b691c9c9d1f8a13 (diff)
XArray: Change xa_for_each iterator
There were three problems with this API: 1. It took too many arguments; almost all users wanted to iterate over every element in the array rather than a subset. 2. It required that 'index' be initialised before use, and there's no realistic way to make GCC catch that. 3. 'index' and 'entry' were the opposite way round from every other member of the XArray APIs. So split it into three different APIs: xa_for_each(xa, index, entry) xa_for_each_start(xa, index, entry, start) xa_for_each_marked(xa, index, entry, filter) Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r--lib/test_xarray.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index a885afde0aef..dc02eff562b8 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -357,7 +357,7 @@ static noinline void check_cmpxchg(struct xarray *xa)
357static noinline void check_reserve(struct xarray *xa) 357static noinline void check_reserve(struct xarray *xa)
358{ 358{
359 void *entry; 359 void *entry;
360 unsigned long index = 0; 360 unsigned long index;
361 361
362 /* An array with a reserved entry is not empty */ 362 /* An array with a reserved entry is not empty */
363 XA_BUG_ON(xa, !xa_empty(xa)); 363 XA_BUG_ON(xa, !xa_empty(xa));
@@ -393,7 +393,7 @@ static noinline void check_reserve(struct xarray *xa)
393 xa_reserve(xa, 6, GFP_KERNEL); 393 xa_reserve(xa, 6, GFP_KERNEL);
394 xa_store_index(xa, 7, GFP_KERNEL); 394 xa_store_index(xa, 7, GFP_KERNEL);
395 395
396 xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { 396 xa_for_each(xa, index, entry) {
397 XA_BUG_ON(xa, index != 5 && index != 7); 397 XA_BUG_ON(xa, index != 5 && index != 7);
398 } 398 }
399 xa_destroy(xa); 399 xa_destroy(xa);
@@ -812,17 +812,16 @@ static noinline void check_find_1(struct xarray *xa)
812static noinline void check_find_2(struct xarray *xa) 812static noinline void check_find_2(struct xarray *xa)
813{ 813{
814 void *entry; 814 void *entry;
815 unsigned long i, j, index = 0; 815 unsigned long i, j, index;
816 816
817 xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { 817 xa_for_each(xa, index, entry) {
818 XA_BUG_ON(xa, true); 818 XA_BUG_ON(xa, true);
819 } 819 }
820 820
821 for (i = 0; i < 1024; i++) { 821 for (i = 0; i < 1024; i++) {
822 xa_store_index(xa, index, GFP_KERNEL); 822 xa_store_index(xa, index, GFP_KERNEL);
823 j = 0; 823 j = 0;
824 index = 0; 824 xa_for_each(xa, index, entry) {
825 xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) {
826 XA_BUG_ON(xa, xa_mk_index(index) != entry); 825 XA_BUG_ON(xa, xa_mk_index(index) != entry);
827 XA_BUG_ON(xa, index != j++); 826 XA_BUG_ON(xa, index != j++);
828 } 827 }