From: Liam R. Howlett Date: Thu, 24 Feb 2022 18:27:22 +0000 (-0500) Subject: maple_tree: Fix stack size again X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f09e1b48f15cb4a60c009a1136bd5aa267d2d36a;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix stack size again Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 64b8a6d6d3a3..bd19e087214e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -118,7 +118,6 @@ struct maple_big_node { unsigned long gap[MAPLE_BIG_NODE_GAPS]; }; }; - unsigned long min; unsigned char b_end; enum maple_type type; }; @@ -1810,12 +1809,11 @@ static inline int mab_no_null_split(struct maple_big_node *b_node, * Return: The first split location. The middle split is set in @mid_split. */ static inline int mab_calc_split(struct ma_state *mas, - struct maple_big_node *bn, - unsigned char *mid_split) + struct maple_big_node *bn, unsigned char *mid_split, unsigned long min) { unsigned char b_end = bn->b_end; int split = b_end / 2; /* Assume equal split. */ - unsigned char min, slot_count = mt_slots[bn->type]; + unsigned char slot_min, slot_count = mt_slots[bn->type]; /* * To support gap tracking, all NULL entries are kept together and a node cannot @@ -1826,11 +1824,11 @@ static inline int mab_calc_split(struct ma_state *mas, if (unlikely((mas->mas_flags & MA_STATE_BULK))) { *mid_split = 0; if (ma_is_leaf(bn->type)) - min = 2; + slot_min = 2; else return b_end - mt_min_slots[bn->type]; - split = b_end - min; + split = b_end - slot_min; mas->mas_flags |= MA_STATE_REBALANCE; if (!bn->slot[split]) split--; @@ -1849,7 +1847,7 @@ static inline int mab_calc_split(struct ma_state *mas, split = b_end / 3; *mid_split = split * 2; } else { - min = mt_min_slots[bn->type]; + slot_min = mt_min_slots[bn->type]; *mid_split = 0; /* @@ -1857,8 +1855,8 @@ static inline int mab_calc_split(struct ma_state *mas, * causes one node to be deficient. * NOTE: mt_min_slots is 1 based, b_end and split are zero. */ - while (((bn->pivot[split] - bn->min) < slot_count - 1) && - (split < slot_count - 1) && (b_end - split > min)) + while (((bn->pivot[split] - min) < slot_count - 1) && + (split < slot_count - 1) && (b_end - split > slot_min)) split++; } @@ -2481,11 +2479,9 @@ static inline struct maple_enode * Return: the split of left. */ static inline unsigned char mas_mab_to_node(struct ma_state *mas, - struct maple_big_node *b_node, - struct maple_enode **left, - struct maple_enode **right, - struct maple_enode **middle, - unsigned char *mid_split) + struct maple_big_node *b_node, struct maple_enode **left, + struct maple_enode **right, struct maple_enode **middle, + unsigned char *mid_split, unsigned long min) { unsigned char split = 0; unsigned char slot_count = mt_slots[b_node->type]; @@ -2498,7 +2494,7 @@ static inline unsigned char mas_mab_to_node(struct ma_state *mas, if (b_node->b_end < slot_count) { split = b_node->b_end; } else { - split = mab_calc_split(mas, b_node, mid_split); + split = mab_calc_split(mas, b_node, mid_split, min); *right = mas_new_ma_node(mas, b_node); } @@ -2767,18 +2763,6 @@ static inline bool mast_overflow(struct maple_subtree_state *mast) return false; } -/* - * mast_setup_bnode_for_split() - Prepare the subtree state big node for - * splitting - * @mast: The maple subtree state - */ -static inline void mast_setup_bnode_for_split(struct maple_subtree_state *mast) -{ - mast->bn->b_end--; - mast->bn->min = mast->orig_l->min; - mast->bn->type = mte_node_type(mast->orig_l->node); -} - static inline void *mtree_range_walk(struct ma_state *mas) { unsigned long *pivots; @@ -2905,9 +2889,10 @@ static int mas_spanning_rebalance(struct ma_state *mas, * See mas_descend_adopt() for more information.. */ while (count--) { - mast_setup_bnode_for_split(mast); + mast->bn->b_end--; + mast->bn->type = mte_node_type(mast->orig_l->node); split = mas_mab_to_node(mas, mast->bn, &left, &right, &middle, - &mid_split); + &mid_split, mast->orig_l->min); mast_set_split_parents(mast, left, middle, right, split, mid_split); mast_cp_to_nodes(mast, left, middle, right, split, mid_split); @@ -3227,7 +3212,6 @@ static inline void mast_fill_bnode(struct maple_subtree_state *mast, mas->offset = mte_parent_slot(mas->node); } - mast->bn->min = mas->min; if (cp && mast->l->offset) mas_mab_cp(mas, 0, mast->l->offset - 1, mast->bn, 0); @@ -3424,7 +3408,7 @@ static int mas_split(struct ma_state *mas, struct maple_big_node *b_node) if (mas_push_data(mas, height, &mast, false)) break; - split = mab_calc_split(mas, b_node, &mid_split); + split = mab_calc_split(mas, b_node, &mid_split, prev_l_mas.min); mast_split_data(&mast, mas, split); /* * Usually correct, mab_mas_cp in the above call overwrites @@ -4239,7 +4223,6 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) slow_path: b_node.b_end = mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end); - b_node.min = mas->min; zero = MAPLE_BIG_NODE_SLOTS - b_node.b_end - 1; memset(b_node.slot + b_node.b_end + 1, 0, sizeof(void *) * zero--); memset(b_node.pivot + b_node.b_end + 1, 0,