Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

maple_tree: clean up mas_wr_node_store()

The new_end does not need to be passed in as the data is already being
checked. This allows for other areas to skip getting the node new_end in
the calling function.

The type was incorrectly void * instead of void __rcu *, which isn't an
issue but is technically incorrect.

Move the variable assignment to after the declarations to clean up the
initial setup.

Ensure there is something to copy before calling memcpy().

Link: https://lkml.kernel.org/r/20260130205935.2559335-31-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrew Ballance <andrewjballance@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Kujau <lists@nerdbynature.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Liam R. Howlett and committed by
Andrew Morton
0e8cf9a3 b82f4c81

+26 -16
+26 -16
lib/maple_tree.c
··· 3122 3122 * 3123 3123 * Attempts to reuse the node, but may allocate. 3124 3124 */ 3125 - static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, 3126 - unsigned char new_end) 3125 + static inline void mas_wr_node_store(struct ma_wr_state *wr_mas) 3127 3126 { 3128 - struct ma_state *mas = wr_mas->mas; 3129 - void __rcu **dst_slots; 3130 - unsigned long *dst_pivots; 3131 - unsigned char dst_offset, offset_end = wr_mas->offset_end; 3127 + unsigned char dst_offset, offset_end; 3128 + unsigned char copy_size, node_pivots; 3132 3129 struct maple_node reuse, *newnode; 3133 - unsigned char copy_size, node_pivots = mt_pivots[wr_mas->type]; 3134 - bool in_rcu = mt_in_rcu(mas->tree); 3135 - unsigned char height = mas_mt_height(mas); 3130 + unsigned long *dst_pivots; 3131 + void __rcu **dst_slots; 3132 + unsigned char new_end; 3133 + struct ma_state *mas; 3134 + bool in_rcu; 3136 3135 3137 - if (mas->last == wr_mas->end_piv) 3136 + mas = wr_mas->mas; 3137 + trace_ma_op(TP_FCT, mas); 3138 + in_rcu = mt_in_rcu(mas->tree); 3139 + offset_end = wr_mas->offset_end; 3140 + node_pivots = mt_pivots[wr_mas->type]; 3141 + /* Assume last adds an entry */ 3142 + new_end = mas->end + 1 - offset_end + mas->offset; 3143 + if (mas->last == wr_mas->end_piv) { 3138 3144 offset_end++; /* don't copy this offset */ 3145 + new_end--; 3146 + } 3139 3147 3140 3148 /* set up node. */ 3141 3149 if (in_rcu) { ··· 3157 3149 dst_pivots = ma_pivots(newnode, wr_mas->type); 3158 3150 dst_slots = ma_slots(newnode, wr_mas->type); 3159 3151 /* Copy from start to insert point */ 3160 - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); 3161 - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); 3152 + if (mas->offset) { 3153 + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); 3154 + memcpy(dst_slots, wr_mas->slots, sizeof(void __rcu *) * mas->offset); 3155 + } 3162 3156 3163 3157 /* Handle insert of new range starting after old range */ 3164 3158 if (wr_mas->r_min < mas->index) { 3165 3159 rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); 3166 3160 dst_pivots[mas->offset++] = mas->index - 1; 3161 + new_end++; 3167 3162 } 3168 3163 3169 3164 /* Store the new entry and range end. */ ··· 3185 3174 /* Copy to the end of node if necessary. */ 3186 3175 copy_size = mas->end - offset_end + 1; 3187 3176 memcpy(dst_slots + dst_offset, wr_mas->slots + offset_end, 3188 - sizeof(void *) * copy_size); 3177 + sizeof(void __rcu *) * copy_size); 3189 3178 memcpy(dst_pivots + dst_offset, wr_mas->pivots + offset_end, 3190 3179 sizeof(unsigned long) * (copy_size - 1)); 3191 3180 ··· 3198 3187 struct maple_enode *old_enode = mas->node; 3199 3188 3200 3189 mas->node = mt_mk_node(newnode, wr_mas->type); 3201 - mas_replace_node(mas, old_enode, height); 3190 + mas_replace_node(mas, old_enode, mas_mt_height(mas)); 3202 3191 } else { 3203 3192 memcpy(wr_mas->node, newnode, sizeof(struct maple_node)); 3204 3193 } ··· 3514 3503 static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) 3515 3504 { 3516 3505 struct ma_state *mas = wr_mas->mas; 3517 - unsigned char new_end = mas_wr_new_end(wr_mas); 3518 3506 3519 3507 switch (mas->store_type) { 3520 3508 case wr_exact_fit: ··· 3528 3518 mas_wr_slot_store(wr_mas); 3529 3519 break; 3530 3520 case wr_node_store: 3531 - mas_wr_node_store(wr_mas, new_end); 3521 + mas_wr_node_store(wr_mas); 3532 3522 break; 3533 3523 case wr_spanning_store: 3534 3524 mas_wr_spanning_store(wr_mas);