From 398384349c2d4a3d60ccfc7671808aa2056c4d20 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Sun, 25 Oct 2020 20:31:56 -0400 Subject: [PATCH] test_maple_tree: Add more allocation checks around overflow Signed-off-by: Liam R. Howlett --- lib/test_maple_tree.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 50cd60f5e04c..bc5414bdb9ec 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -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); } -- 2.50.1