]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Correct encoding maple nodes
authorMatthew Wilcox <willy@infradead.org>
Tue, 27 Nov 2018 22:03:59 +0000 (17:03 -0500)
committerMatthew Wilcox <willy@infradead.org>
Tue, 27 Nov 2018 22:08:07 +0000 (17:08 -0500)
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 <willy@infradead.org>
lib/maple_tree.c

index d0dfd10355daa9003370b607a1d066dcca10f3f3..0ceac146f296bc37b40c3ae4eda753d1750c2c8b 100644 (file)
@@ -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;