4 * Helper radix_tree_iter_retry resets next_index to the current index.
5 * In following radix_tree_next_slot current chunk size becomes zero.
6 * This isn't checked and it tries to dereference null pointer in slot.
8 * Helper radix_tree_iter_next reset slot to NULL and next_index to index + 1,
9 * for tagger iteraction it also must reset cached tags in iterator to abort
10 * next radix_tree_next_slot and go to slow-path into radix_tree_next_chunk.
13 * This test should run to completion immediately. The above bug would
14 * cause it to segfault.
19 #include <linux/kernel.h>
20 #include <linux/gfp.h>
21 #include <linux/slab.h>
22 #include <linux/radix-tree.h>
26 #include "regression.h"
28 void regression3_test(void)
30 RADIX_TREE(root, GFP_KERNEL);
31 void *ptr0 = (void *)4ul;
32 void *ptr = (void *)8ul;
33 struct radix_tree_iter iter;
37 printf("running regression test 3 (should take milliseconds)\n");
39 radix_tree_insert(&root, 0, ptr0);
40 radix_tree_tag_set(&root, 0, 0);
43 radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) {
44 printf("tagged %ld %p\n", iter.index, *slot);
46 radix_tree_insert(&root, 1, ptr);
47 radix_tree_tag_set(&root, 1, 0);
50 if (radix_tree_deref_retry(*slot)) {
51 printf("retry at %ld\n", iter.index);
52 slot = radix_tree_iter_retry(&iter);
56 radix_tree_delete(&root, 1);
59 radix_tree_for_each_slot(slot, &root, &iter, 0) {
60 printf("slot %ld %p\n", iter.index, *slot);
62 radix_tree_insert(&root, 1, ptr);
65 if (radix_tree_deref_retry(*slot)) {
66 printk("retry at %ld\n", iter.index);
67 slot = radix_tree_iter_retry(&iter);
71 radix_tree_delete(&root, 1);
74 radix_tree_for_each_contig(slot, &root, &iter, 0) {
75 printk("contig %ld %p\n", iter.index, *slot);
77 radix_tree_insert(&root, 1, ptr);
80 if (radix_tree_deref_retry(*slot)) {
81 printk("retry at %ld\n", iter.index);
82 slot = radix_tree_iter_retry(&iter);
87 radix_tree_for_each_slot(slot, &root, &iter, 0) {
88 printf("slot %ld %p\n", iter.index, *slot);
90 printf("next at %ld\n", iter.index);
91 slot = radix_tree_iter_next(&iter);
95 radix_tree_for_each_contig(slot, &root, &iter, 0) {
96 printf("contig %ld %p\n", iter.index, *slot);
98 printf("next at %ld\n", iter.index);
99 slot = radix_tree_iter_next(&iter);
103 radix_tree_tag_set(&root, 0, 0);
104 radix_tree_tag_set(&root, 1, 0);
105 radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) {
106 printf("tagged %ld %p\n", iter.index, *slot);
108 printf("next at %ld\n", iter.index);
109 slot = radix_tree_iter_next(&iter);
113 radix_tree_delete(&root, 0);
114 radix_tree_delete(&root, 1);
116 printf("regression test 3 passed\n");