diff mbox series

[09/18] maple_tree: use mas_store_gfp() in mtree_store_range()

Message ID 20240604174145.563900-10-sidhartha.kumar@oracle.com (mailing list archive)
State New
Headers show
Series Introduce a store type enum for the Maple tree | expand

Commit Message

Sidhartha Kumar June 4, 2024, 5:41 p.m. UTC
Refactor mtree_store_range() to use mas_store_gfp() which will abstract
the store, memory allocation, and error handling.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
 lib/maple_tree.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Liam R. Howlett June 4, 2024, 7:24 p.m. UTC | #1
* Sidhartha Kumar <sidhartha.kumar@oracle.com> [240604 13:42]:
> Refactor mtree_store_range() to use mas_store_gfp() which will abstract
> the store, memory allocation, and error handling.
> 
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
>  lib/maple_tree.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 34ff1b3f729c..e3ec6649f7da 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -6457,7 +6457,6 @@ int mtree_store_range(struct maple_tree *mt, unsigned long index,
>  		unsigned long last, void *entry, gfp_t gfp)
>  {
>  	MA_STATE(mas, mt, index, last);
> -	MA_WR_STATE(wr_mas, &mas, entry);
>  	int ret = 0;
>  
>  	trace_ma_write(__func__, &mas, 0, entry);
> @@ -6468,17 +6467,10 @@ int mtree_store_range(struct maple_tree *mt, unsigned long index,
>  		return -EINVAL;
>  
>  	mtree_lock(mt);
> -retry:
> -	mas_wr_store_entry(&wr_mas);
> -	if (mas_nomem(&mas, gfp))
> -		goto retry;
> -
> +	ret = mas_store_gfp(&mas, entry, gfp);
>  	mtree_unlock(mt);
>  
> -	if (mas_is_err(&mas))
> -		ret = xa_err(mas.node);
> -
> -	mas_destroy(&mas);
> +	MT_BUG_ON(mas.tree, mas.store_type == wr_invalid);

This check should be inside the lock as it dumps the tree.

>  	return ret;
>  }
>  EXPORT_SYMBOL(mtree_store_range);
> -- 
> 2.45.1
>
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 34ff1b3f729c..e3ec6649f7da 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -6457,7 +6457,6 @@  int mtree_store_range(struct maple_tree *mt, unsigned long index,
 		unsigned long last, void *entry, gfp_t gfp)
 {
 	MA_STATE(mas, mt, index, last);
-	MA_WR_STATE(wr_mas, &mas, entry);
 	int ret = 0;
 
 	trace_ma_write(__func__, &mas, 0, entry);
@@ -6468,17 +6467,10 @@  int mtree_store_range(struct maple_tree *mt, unsigned long index,
 		return -EINVAL;
 
 	mtree_lock(mt);
-retry:
-	mas_wr_store_entry(&wr_mas);
-	if (mas_nomem(&mas, gfp))
-		goto retry;
-
+	ret = mas_store_gfp(&mas, entry, gfp);
 	mtree_unlock(mt);
 
-	if (mas_is_err(&mas))
-		ret = xa_err(mas.node);
-
-	mas_destroy(&mas);
+	MT_BUG_ON(mas.tree, mas.store_type == wr_invalid);
 	return ret;
 }
 EXPORT_SYMBOL(mtree_store_range);