]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Export mas_empty_alloc() for mas_for_each pre-allocations
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Sun, 11 Oct 2020 18:18:05 +0000 (14:18 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:13:08 +0000 (15:13 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c

index eecf046cab0582563b745fd40df8b666bc517f99..09b64012a85d1e0c3f42ea79cbacd7c1106830a6 100644 (file)
@@ -396,6 +396,7 @@ static inline void mt_set_in_rcu(struct maple_tree *mt)
 }
 
 int mas_entry_count(struct ma_state *mas, unsigned long nr_leaves);
+void mas_empty_alloc(struct ma_state *mas);
 
 void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max);
 void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max,
index 25fe27927fa321880c281d7ce4c805e7f7284a73..5fbaa9914d1669fb739102f52171c9a83117d24c 100644 (file)
@@ -948,7 +948,7 @@ list_failed:
 }
 
 // Free the allocations.
-static inline void mas_empty_alloc(struct ma_state *mas)
+void mas_empty_alloc(struct ma_state *mas)
 {
        struct maple_node *node;
 
@@ -995,9 +995,12 @@ static inline struct maple_node *mas_node_cnt(struct ma_state *mas, int count)
        return mas->alloc;
 }
 
-int mas_entry_count(struct ma_state *mas, unsigned long nr_entries) {
+int mas_entry_count(struct ma_state *mas, unsigned long nr_entries)
+{
        int nonleaf_cap = MAPLE_ARANGE64_SLOTS - 1;
+       struct maple_enode *enode = mas->node;
        int nr_nodes;
+       int ret;
 
        if (!mt_is_alloc(mas->tree))
            nonleaf_cap = MAPLE_RANGE64_SLOTS - 1;
@@ -1005,9 +1008,13 @@ int mas_entry_count(struct ma_state *mas, unsigned long nr_entries) {
        nr_nodes = DIV_ROUND_UP(nr_entries, MAPLE_RANGE64_SLOTS); // leaves
        nr_nodes += DIV_ROUND_UP(nr_nodes, nonleaf_cap);
        mas_node_cnt(mas, min(nr_nodes, (int)MAPLE_NODE_MAX));
+
        if (!mas_is_err(mas))
                return 0;
-       return xa_err(mas->node);
+
+       ret = xa_err(mas->node);
+       mas->node = enode;
+       return ret;
 
 }
 /*