]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
test_maple_tree: Add more allocation checks around overflow
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 26 Oct 2020 00:31:56 +0000 (20:31 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:13:31 +0000 (15:13 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/test_maple_tree.c

index 50cd60f5e04ce02b9518ec5c56337397e34739bf..bc5414bdb9ec179ad9ec5481f70383bf35951862 100644 (file)
@@ -407,6 +407,46 @@ static noinline void check_new_node(struct maple_tree *mt)
                MT_BUG_ON(mt, mas_allocated(&mas2) != 0);
        }
 
+
+       MT_BUG_ON(mt, mas_allocated(&mas) != 0);
+       mas_node_count(&mas, MAPLE_NODE_SLOTS); // Request
+       MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM));
+       MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL));
+       printk("alloc node total %u\n", mas.alloc->total);
+       MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_NODE_SLOTS);
+       printk("alloc node count %u\n", mas.alloc->node_count);
+       MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_NODE_SLOTS - 2);
+
+       mn = mas_pop_node(&mas); // get the next node.
+       printk("alloc node count %u\n", mas.alloc->node_count);
+       MT_BUG_ON(mt, mn == NULL);
+       MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_NODE_SLOTS - 3);
+       MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_NODE_SLOTS - 1);
+
+       mas_push_node(&mas, (struct maple_enode *)mn);
+       printk("alloc node count %u\n", mas.alloc->node_count);
+       MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_NODE_SLOTS - 2);
+       MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_NODE_SLOTS);
+
+       printk("Add one on the end\n");
+       printk("alloc node count %u\n", mas.alloc->node_count);
+       printk("alloc node total %u\n", mas.alloc->total);
+       printk("Request %u\n", MAPLE_NODE_SLOTS + 1);
+       mas_node_count(&mas, MAPLE_NODE_SLOTS + 1); // Request
+       printk("alloc req %u\n", mas_alloc_req(&mas));
+       MT_BUG_ON(mt, mas_alloc_req(&mas) != 1);
+       MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM));
+       MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL));
+       MT_BUG_ON(mt, mas_alloc_req(&mas));
+       printk("alloc node count %u\n", mas.alloc->node_count);
+       printk("alloc node total %u\n", mas.alloc->total);
+       mn = mas_pop_node(&mas);
+       ma_free_rcu(mn);
+       for (i = 1; i <= MAPLE_NODE_SLOTS; i++) {
+               mn = mas_pop_node(&mas);
+               ma_free_rcu(mn);
+       }
+       MT_BUG_ON(mt, mas_allocated(&mas) != 0);
        mtree_unlock(mt);
        mtree_destroy(mt);
 }