int mtree_destroy(struct maple_tree *mt);
+/**
+ * mtree_empty() - Determine if a tree has any present entries.
+ * @mt: Maple Tree.
+ *
+ * Context: Any context.
+ * Return: %true if the array contains only NULL pointers.
+ */
+static inline bool mtree_empty(const struct maple_tree *mt)
+{
+ return mt->root == NULL;
+}
+
#endif
} while (0)
#endif
+static
+int mtree_insert_index(struct maple_tree *mt, unsigned long index, gfp_t gfp)
+{
+ return mtree_insert(mt, index, xa_mk_value(index & LONG_MAX), gfp);
+}
static int mtree_test_insert(struct maple_tree *mt, unsigned long index,
void *ptr)
{
return mtree_insert(mt, index, ptr, GFP_KERNEL);
}
+
static int mtree_test_insert_range(struct maple_tree *mt, unsigned long start,
unsigned long end, void *ptr)
{
MT_BUG_ON(mt, ret != ptr);
}
+static noinline void check_nomem(struct maple_tree *mt)
+{
+ MT_BUG_ON(mt, !mtree_empty(mt));
+
+ /* Storing something at 1 requires memory allocation */
+ MT_BUG_ON(mt, mtree_insert_index(mt, 1, GFP_ATOMIC) != -ENOMEM);
+ /* Storing something at 0 does not */
+ MT_BUG_ON(mt, mtree_insert_index(mt, 0, GFP_ATOMIC) != 0);
+
+ mtree_destroy(mt);
+}
+
static DEFINE_MAPLE_TREE(tree);
static int maple_tree_seed(void)
check_load(&tree, set[9], &tree);
mtree_destroy(&tree);
+ check_nomem(&tree);
-
printk("maple_tree: %u of %u tests passed\n", tests_passed, tests_run);
return (tests_run == tests_passed) ? 0 : -EINVAL;
}