Commit 611f3186 authored by Matthew Wilcox's avatar Matthew Wilcox

XArray: Unify xa_store and __xa_store

Saves around 115 bytes on a tinyconfig build and reduces the amount
of code duplication in the XArray implementation.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent 84e5acb7
...@@ -1361,23 +1361,21 @@ void *xa_erase(struct xarray *xa, unsigned long index) ...@@ -1361,23 +1361,21 @@ void *xa_erase(struct xarray *xa, unsigned long index)
EXPORT_SYMBOL(xa_erase); EXPORT_SYMBOL(xa_erase);
/** /**
* xa_store() - Store this entry in the XArray. * __xa_store() - Store this entry in the XArray.
* @xa: XArray. * @xa: XArray.
* @index: Index into array. * @index: Index into array.
* @entry: New entry. * @entry: New entry.
* @gfp: Memory allocation flags. * @gfp: Memory allocation flags.
* *
* After this function returns, loads from this index will return @entry. * You must already be holding the xa_lock when calling this function.
* Storing into an existing multislot entry updates the entry of every index. * It will drop the lock if needed to allocate memory, and then reacquire
* The marks associated with @index are unaffected unless @entry is %NULL. * it afterwards.
* *
* Context: Process context. Takes and releases the xa_lock. May sleep * Context: Any context. Expects xa_lock to be held on entry. May
* if the @gfp flags permit. * release and reacquire xa_lock if @gfp flags permit.
* Return: The old entry at this index on success, xa_err(-EINVAL) if @entry * Return: The old entry at this index or xa_err() if an error happened.
* cannot be stored in an XArray, or xa_err(-ENOMEM) if memory allocation
* failed.
*/ */
void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
{ {
XA_STATE(xas, xa, index); XA_STATE(xas, xa, index);
void *curr; void *curr;
...@@ -1386,49 +1384,43 @@ void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) ...@@ -1386,49 +1384,43 @@ void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
return XA_ERROR(-EINVAL); return XA_ERROR(-EINVAL);
do { do {
xas_lock(&xas);
curr = xas_store(&xas, entry); curr = xas_store(&xas, entry);
if (xa_track_free(xa) && entry) if (xa_track_free(xa) && entry)
xas_clear_mark(&xas, XA_FREE_MARK); xas_clear_mark(&xas, XA_FREE_MARK);
xas_unlock(&xas); } while (__xas_nomem(&xas, gfp));
} while (xas_nomem(&xas, gfp));
return xas_result(&xas, curr); return xas_result(&xas, curr);
} }
EXPORT_SYMBOL(xa_store); EXPORT_SYMBOL(__xa_store);
/** /**
* __xa_store() - Store this entry in the XArray. * xa_store() - Store this entry in the XArray.
* @xa: XArray. * @xa: XArray.
* @index: Index into array. * @index: Index into array.
* @entry: New entry. * @entry: New entry.
* @gfp: Memory allocation flags. * @gfp: Memory allocation flags.
* *
* You must already be holding the xa_lock when calling this function. * After this function returns, loads from this index will return @entry.
* It will drop the lock if needed to allocate memory, and then reacquire * Storing into an existing multislot entry updates the entry of every index.
* it afterwards. * The marks associated with @index are unaffected unless @entry is %NULL.
* *
* Context: Any context. Expects xa_lock to be held on entry. May * Context: Any context. Takes and releases the xa_lock.
* release and reacquire xa_lock if @gfp flags permit. * May sleep if the @gfp flags permit.
* Return: The old entry at this index or xa_err() if an error happened. * Return: The old entry at this index on success, xa_err(-EINVAL) if @entry
* cannot be stored in an XArray, or xa_err(-ENOMEM) if memory allocation
* failed.
*/ */
void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
{ {
XA_STATE(xas, xa, index);
void *curr; void *curr;
if (WARN_ON_ONCE(xa_is_internal(entry))) xa_lock(xa);
return XA_ERROR(-EINVAL); curr = __xa_store(xa, index, entry, gfp);
xa_unlock(xa);
do {
curr = xas_store(&xas, entry);
if (xa_track_free(xa) && entry)
xas_clear_mark(&xas, XA_FREE_MARK);
} while (__xas_nomem(&xas, gfp));
return xas_result(&xas, curr); return curr;
} }
EXPORT_SYMBOL(__xa_store); EXPORT_SYMBOL(xa_store);
/** /**
* __xa_cmpxchg() - Store this entry in the XArray. * __xa_cmpxchg() - Store this entry in the XArray.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment