From d47b8f1c023d29de5807b393a9f232be2f96d886 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Tue, 27 Nov 2018 17:03:59 -0500 Subject: [PATCH] maple_tree: Correct encoding maple nodes Don't shift; we'll lose the top two bits. Instead just OR in bit 1 to ensure this pointer is seen as a node pointer, and subtract off 2, just like the XArray does for turning nodes into entries and vice versa. Also don't return an entry from _maple_new_node(), return a node and let the caller take care of turning it into an entry, if it needs an entry. Also don't use GFP_NOWAIT in mtree_init(). Signed-off-by: Matthew Wilcox --- lib/maple_tree.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index d0dfd10355da..0ceac146f296 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -76,9 +76,15 @@ static inline bool _is_root(struct maple_state *ms) return true; return false; } + static inline struct maple_node *_maple_to_node(const void *entry) { - return (struct maple_node *)(xa_to_internal(entry)); + return (struct maple_node *)((unsigned long)entry - 2); +} + +static inline void *_maple_mk_node(const struct maple_node *node) +{ + return (void *)((unsigned long)node | 2); } static inline bool _maple_is_node_4(struct maple_state *ms) { @@ -90,7 +96,7 @@ static inline bool _maple_is_node_4(struct maple_state *ms) { return false; } -static void *_maple_new_node(gfp_t gfp) +static struct maple_node *_maple_new_node(gfp_t gfp) { struct maple_node *mn; size_t size = sizeof(struct maple_node); @@ -99,7 +105,6 @@ static void *_maple_new_node(gfp_t gfp) goto kmalloc_failed; mn->map64.parent = NULL; - mn = xa_mk_internal((unsigned long)mn); kmalloc_failed: return mn; @@ -472,7 +477,7 @@ void mtree_init(struct maple_tree *mt) { spin_lock_init(&mt->lock); mt->flags = 0; - mt->root = _maple_new_node(GFP_KERNEL | GFP_NOWAIT | __GFP_ZERO); + mt->root = _maple_mk_node(_maple_new_node(GFP_KERNEL | __GFP_ZERO)); mt->min = 0; mt->max = ULONG_MAX; -- 2.50.1