diff options
author | Matthew Wilcox <willy@infradead.org> | 2019-02-20 11:51:22 -0500 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2019-02-20 17:08:54 -0500 |
commit | 962033d55d0761e0716a01a715c6659c8c8dfc41 (patch) | |
tree | 436d84076c3e16836a59efe46b75d2900a560add /lib/xarray.c | |
parent | b38f6c50270683abf35a388f82cafecce971a003 (diff) |
XArray: Use xa_cmpxchg to implement xa_reserve
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>
Diffstat (limited to 'lib/xarray.c')
-rw-r--r-- | lib/xarray.c | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/lib/xarray.c b/lib/xarray.c index b9a6cf42feee..3f10198f00b7 100644 --- a/lib/xarray.c +++ b/lib/xarray.c | |||
@@ -1484,42 +1484,6 @@ int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) | |||
1484 | } | 1484 | } |
1485 | EXPORT_SYMBOL(__xa_insert); | 1485 | EXPORT_SYMBOL(__xa_insert); |
1486 | 1486 | ||
1487 | /** | ||
1488 | * __xa_reserve() - Reserve this index in the XArray. | ||
1489 | * @xa: XArray. | ||
1490 | * @index: Index into array. | ||
1491 | * @gfp: Memory allocation flags. | ||
1492 | * | ||
1493 | * Ensures there is somewhere to store an entry at @index in the array. | ||
1494 | * If there is already something stored at @index, this function does | ||
1495 | * nothing. If there was nothing there, the entry is marked as reserved. | ||
1496 | * Loading from a reserved entry returns a %NULL pointer. | ||
1497 | * | ||
1498 | * If you do not use the entry that you have reserved, call xa_release() | ||
1499 | * or xa_erase() to free any unnecessary memory. | ||
1500 | * | ||
1501 | * Context: Any context. Expects the xa_lock to be held on entry. May | ||
1502 | * release the lock, sleep and reacquire the lock if the @gfp flags permit. | ||
1503 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | ||
1504 | */ | ||
1505 | int __xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) | ||
1506 | { | ||
1507 | XA_STATE(xas, xa, index); | ||
1508 | void *curr; | ||
1509 | |||
1510 | do { | ||
1511 | curr = xas_load(&xas); | ||
1512 | if (!curr) { | ||
1513 | xas_store(&xas, XA_ZERO_ENTRY); | ||
1514 | if (xa_track_free(xa)) | ||
1515 | xas_clear_mark(&xas, XA_FREE_MARK); | ||
1516 | } | ||
1517 | } while (__xas_nomem(&xas, gfp)); | ||
1518 | |||
1519 | return xas_error(&xas); | ||
1520 | } | ||
1521 | EXPORT_SYMBOL(__xa_reserve); | ||
1522 | |||
1523 | #ifdef CONFIG_XARRAY_MULTI | 1487 | #ifdef CONFIG_XARRAY_MULTI |
1524 | static void xas_set_range(struct xa_state *xas, unsigned long first, | 1488 | static void xas_set_range(struct xa_state *xas, unsigned long first, |
1525 | unsigned long last) | 1489 | unsigned long last) |