]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
XArray: Use xa_cmpxchg to implement xa_reserve
authorMatthew Wilcox <willy@infradead.org>
Wed, 20 Feb 2019 16:51:22 +0000 (11:51 -0500)
committerMatthew Wilcox <willy@infradead.org>
Wed, 20 Feb 2019 22:08:54 +0000 (17:08 -0500)
Jason feels this is clearer, and it saves a function and an exported
symbol.

Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Documentation/core-api/xarray.rst
include/linux/xarray.h
lib/xarray.c

index c7436da5c4ad0f8bac2af9767deaf1833399d990..ef6f9f98f59572c424af48394b7f1a4aac22388e 100644 (file)
@@ -215,7 +215,6 @@ Assumes xa_lock held on entry:
  * :c:func:`__xa_erase`
  * :c:func:`__xa_cmpxchg`
  * :c:func:`__xa_alloc`
- * :c:func:`__xa_reserve`
  * :c:func:`__xa_set_mark`
  * :c:func:`__xa_clear_mark`
 
index 588733abd19d7457b3b9075ed174b0f0e780caf9..0e01e612914554897369a6a359ddad16573b4cb6 100644 (file)
@@ -525,7 +525,6 @@ int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry,
                struct xa_limit, gfp_t);
 int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry,
                struct xa_limit, u32 *next, gfp_t);
-int __must_check __xa_reserve(struct xarray *, unsigned long index, gfp_t);
 void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t);
 void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t);
 
@@ -1004,13 +1003,7 @@ static inline int xa_alloc_cyclic_irq(struct xarray *xa, u32 *id, void *entry,
 static inline __must_check
 int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
 {
-       int ret;
-
-       xa_lock(xa);
-       ret = __xa_reserve(xa, index, gfp);
-       xa_unlock(xa);
-
-       return ret;
+       return xa_err(xa_cmpxchg(xa, index, NULL, XA_ZERO_ENTRY, gfp));
 }
 
 /**
@@ -1028,13 +1021,7 @@ int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
 static inline __must_check
 int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp)
 {
-       int ret;
-
-       xa_lock_bh(xa);
-       ret = __xa_reserve(xa, index, gfp);
-       xa_unlock_bh(xa);
-
-       return ret;
+       return xa_err(xa_cmpxchg_bh(xa, index, NULL, XA_ZERO_ENTRY, gfp));
 }
 
 /**
@@ -1052,13 +1039,7 @@ int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp)
 static inline __must_check
 int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp)
 {
-       int ret;
-
-       xa_lock_irq(xa);
-       ret = __xa_reserve(xa, index, gfp);
-       xa_unlock_irq(xa);
-
-       return ret;
+       return xa_err(xa_cmpxchg_irq(xa, index, NULL, XA_ZERO_ENTRY, gfp));
 }
 
 /**
index b9a6cf42feeea293c2dca33cefc8e14f8f2bf31c..3f10198f00b77cc149203a89c7b631bbcf1ba708 100644 (file)
@@ -1484,42 +1484,6 @@ int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
 }
 EXPORT_SYMBOL(__xa_insert);
 
-/**
- * __xa_reserve() - Reserve this index in the XArray.
- * @xa: XArray.
- * @index: Index into array.
- * @gfp: Memory allocation flags.
- *
- * Ensures there is somewhere to store an entry at @index in the array.
- * If there is already something stored at @index, this function does
- * nothing.  If there was nothing there, the entry is marked as reserved.
- * Loading from a reserved entry returns a %NULL pointer.
- *
- * If you do not use the entry that you have reserved, call xa_release()
- * or xa_erase() to free any unnecessary memory.
- *
- * Context: Any context.  Expects the xa_lock to be held on entry.  May
- * release the lock, sleep and reacquire the lock if the @gfp flags permit.
- * Return: 0 if the reservation succeeded or -ENOMEM if it failed.
- */
-int __xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
-{
-       XA_STATE(xas, xa, index);
-       void *curr;
-
-       do {
-               curr = xas_load(&xas);
-               if (!curr) {
-                       xas_store(&xas, XA_ZERO_ENTRY);
-                       if (xa_track_free(xa))
-                               xas_clear_mark(&xas, XA_FREE_MARK);
-               }
-       } while (__xas_nomem(&xas, gfp));
-
-       return xas_error(&xas);
-}
-EXPORT_SYMBOL(__xa_reserve);
-
 #ifdef CONFIG_XARRAY_MULTI
 static void xas_set_range(struct xa_state *xas, unsigned long first,
                unsigned long last)