summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2019-02-20 11:51:22 -0500
committerMatthew Wilcox <willy@infradead.org>2019-02-20 17:08:54 -0500
commit962033d55d0761e0716a01a715c6659c8c8dfc41 (patch)
tree436d84076c3e16836a59efe46b75d2900a560add
parentb38f6c50270683abf35a388f82cafecce971a003 (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>
-rw-r--r--Documentation/core-api/xarray.rst1
-rw-r--r--include/linux/xarray.h25
-rw-r--r--lib/xarray.c36
3 files changed, 3 insertions, 59 deletions
diff --git a/Documentation/core-api/xarray.rst b/Documentation/core-api/xarray.rst
index c7436da5c4ad..ef6f9f98f595 100644
--- a/Documentation/core-api/xarray.rst
+++ b/Documentation/core-api/xarray.rst
@@ -215,7 +215,6 @@ Assumes xa_lock held on entry:
215 * :c:func:`__xa_erase` 215 * :c:func:`__xa_erase`
216 * :c:func:`__xa_cmpxchg` 216 * :c:func:`__xa_cmpxchg`
217 * :c:func:`__xa_alloc` 217 * :c:func:`__xa_alloc`
218 * :c:func:`__xa_reserve`
219 * :c:func:`__xa_set_mark` 218 * :c:func:`__xa_set_mark`
220 * :c:func:`__xa_clear_mark` 219 * :c:func:`__xa_clear_mark`
221 220
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 588733abd19d..0e01e6129145 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -525,7 +525,6 @@ int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry,
525 struct xa_limit, gfp_t); 525 struct xa_limit, gfp_t);
526int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry, 526int __must_check __xa_alloc_cyclic(struct xarray *, u32 *id, void *entry,
527 struct xa_limit, u32 *next, gfp_t); 527 struct xa_limit, u32 *next, gfp_t);
528int __must_check __xa_reserve(struct xarray *, unsigned long index, gfp_t);
529void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t); 528void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t);
530void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t); 529void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t);
531 530
@@ -1004,13 +1003,7 @@ static inline int xa_alloc_cyclic_irq(struct xarray *xa, u32 *id, void *entry,
1004static inline __must_check 1003static inline __must_check
1005int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) 1004int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
1006{ 1005{
1007 int ret; 1006 return xa_err(xa_cmpxchg(xa, index, NULL, XA_ZERO_ENTRY, gfp));
1008
1009 xa_lock(xa);
1010 ret = __xa_reserve(xa, index, gfp);
1011 xa_unlock(xa);
1012
1013 return ret;
1014} 1007}
1015 1008
1016/** 1009/**
@@ -1028,13 +1021,7 @@ int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp)
1028static inline __must_check 1021static inline __must_check
1029int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) 1022int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp)
1030{ 1023{
1031 int ret; 1024 return xa_err(xa_cmpxchg_bh(xa, index, NULL, XA_ZERO_ENTRY, gfp));
1032
1033 xa_lock_bh(xa);
1034 ret = __xa_reserve(xa, index, gfp);
1035 xa_unlock_bh(xa);
1036
1037 return ret;
1038} 1025}
1039 1026
1040/** 1027/**
@@ -1052,13 +1039,7 @@ int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp)
1052static inline __must_check 1039static inline __must_check
1053int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp) 1040int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp)
1054{ 1041{
1055 int ret; 1042 return xa_err(xa_cmpxchg_irq(xa, index, NULL, XA_ZERO_ENTRY, gfp));
1056
1057 xa_lock_irq(xa);
1058 ret = __xa_reserve(xa, index, gfp);
1059 xa_unlock_irq(xa);
1060
1061 return ret;
1062} 1043}
1063 1044
1064/** 1045/**
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}
1485EXPORT_SYMBOL(__xa_insert); 1485EXPORT_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 */
1505int __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}
1521EXPORT_SYMBOL(__xa_reserve);
1522
1523#ifdef CONFIG_XARRAY_MULTI 1487#ifdef CONFIG_XARRAY_MULTI
1524static void xas_set_range(struct xa_state *xas, unsigned long first, 1488static void xas_set_range(struct xa_state *xas, unsigned long first,
1525 unsigned long last) 1489 unsigned long last)