diff options
Diffstat (limited to 'lib/xarray.c')
-rw-r--r-- | lib/xarray.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/xarray.c b/lib/xarray.c index 468fb7b7963f..c707388fb05e 100644 --- a/lib/xarray.c +++ b/lib/xarray.c | |||
@@ -1615,23 +1615,23 @@ EXPORT_SYMBOL(xa_store_range); | |||
1615 | * __xa_alloc() - Find somewhere to store this entry in the XArray. | 1615 | * __xa_alloc() - Find somewhere to store this entry in the XArray. |
1616 | * @xa: XArray. | 1616 | * @xa: XArray. |
1617 | * @id: Pointer to ID. | 1617 | * @id: Pointer to ID. |
1618 | * @max: Maximum ID to allocate (inclusive). | 1618 | * @limit: Range for allocated ID. |
1619 | * @entry: New entry. | 1619 | * @entry: New entry. |
1620 | * @gfp: Memory allocation flags. | 1620 | * @gfp: Memory allocation flags. |
1621 | * | 1621 | * |
1622 | * Allocates an unused ID in the range specified by @id and @max. | 1622 | * Finds an empty entry in @xa between @limit.min and @limit.max, |
1623 | * Updates the @id pointer with the index, then stores the entry at that | 1623 | * stores the index into the @id pointer, then stores the entry at |
1624 | * index. A concurrent lookup will not see an uninitialised @id. | 1624 | * that index. A concurrent lookup will not see an uninitialised @id. |
1625 | * | 1625 | * |
1626 | * Context: Any context. Expects xa_lock to be held on entry. May | 1626 | * Context: Any context. Expects xa_lock to be held on entry. May |
1627 | * release and reacquire xa_lock if @gfp flags permit. | 1627 | * release and reacquire xa_lock if @gfp flags permit. |
1628 | * Return: 0 on success, -ENOMEM if memory allocation fails or -ENOSPC if | 1628 | * Return: 0 on success, -ENOMEM if memory could not be allocated or |
1629 | * there is no more space in the XArray. | 1629 | * -EBUSY if there are no free entries in @limit. |
1630 | */ | 1630 | */ |
1631 | int __xa_alloc(struct xarray *xa, u32 *id, u32 max, void *entry, gfp_t gfp) | 1631 | int __xa_alloc(struct xarray *xa, u32 *id, void *entry, |
1632 | struct xa_limit limit, gfp_t gfp) | ||
1632 | { | 1633 | { |
1633 | XA_STATE(xas, xa, 0); | 1634 | XA_STATE(xas, xa, 0); |
1634 | int err; | ||
1635 | 1635 | ||
1636 | if (WARN_ON_ONCE(xa_is_advanced(entry))) | 1636 | if (WARN_ON_ONCE(xa_is_advanced(entry))) |
1637 | return -EINVAL; | 1637 | return -EINVAL; |
@@ -1642,18 +1642,17 @@ int __xa_alloc(struct xarray *xa, u32 *id, u32 max, void *entry, gfp_t gfp) | |||
1642 | entry = XA_ZERO_ENTRY; | 1642 | entry = XA_ZERO_ENTRY; |
1643 | 1643 | ||
1644 | do { | 1644 | do { |
1645 | xas.xa_index = *id; | 1645 | xas.xa_index = limit.min; |
1646 | xas_find_marked(&xas, max, XA_FREE_MARK); | 1646 | xas_find_marked(&xas, limit.max, XA_FREE_MARK); |
1647 | if (xas.xa_node == XAS_RESTART) | 1647 | if (xas.xa_node == XAS_RESTART) |
1648 | xas_set_err(&xas, -ENOSPC); | 1648 | xas_set_err(&xas, -EBUSY); |
1649 | else | ||
1650 | *id = xas.xa_index; | ||
1649 | xas_store(&xas, entry); | 1651 | xas_store(&xas, entry); |
1650 | xas_clear_mark(&xas, XA_FREE_MARK); | 1652 | xas_clear_mark(&xas, XA_FREE_MARK); |
1651 | } while (__xas_nomem(&xas, gfp)); | 1653 | } while (__xas_nomem(&xas, gfp)); |
1652 | 1654 | ||
1653 | err = xas_error(&xas); | 1655 | return xas_error(&xas); |
1654 | if (!err) | ||
1655 | *id = xas.xa_index; | ||
1656 | return err; | ||
1657 | } | 1656 | } |
1658 | EXPORT_SYMBOL(__xa_alloc); | 1657 | EXPORT_SYMBOL(__xa_alloc); |
1659 | 1658 | ||