From 9ca51a66c166484d3e0a136077b70a6a1faa683c Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Sun, 11 Oct 2020 14:18:05 -0400 Subject: [PATCH] maple_tree: Export mas_empty_alloc() for mas_for_each pre-allocations Signed-off-by: Liam R. Howlett --- include/linux/maple_tree.h | 1 + lib/maple_tree.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index eecf046cab05..09b64012a85d 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -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, diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 25fe27927fa3..5fbaa9914d16 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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; } /* -- 2.50.1