diff options
author | Matthew Wilcox <willy@infradead.org> | 2017-11-17 08:16:34 -0500 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2018-10-21 10:45:59 -0400 |
commit | 687149fca1f37c447e5d161e0a4a04cb2c880cb6 (patch) | |
tree | 5134bc243622997b10644a67a55ee51e6278930a /lib/xarray.c | |
parent | 80a0a1a9a3cde9b23851e8eb7160e2786549306a (diff) |
xarray: Destroy an XArray
This function frees all the internal memory allocated to the xarray
and reinitialises it to be empty.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/xarray.c')
-rw-r--r-- | lib/xarray.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/xarray.c b/lib/xarray.c index 70e04810c8c2..057dbe0d3bf6 100644 --- a/lib/xarray.c +++ b/lib/xarray.c | |||
@@ -1524,6 +1524,34 @@ unsigned int xa_extract(struct xarray *xa, void **dst, unsigned long start, | |||
1524 | } | 1524 | } |
1525 | EXPORT_SYMBOL(xa_extract); | 1525 | EXPORT_SYMBOL(xa_extract); |
1526 | 1526 | ||
1527 | /** | ||
1528 | * xa_destroy() - Free all internal data structures. | ||
1529 | * @xa: XArray. | ||
1530 | * | ||
1531 | * After calling this function, the XArray is empty and has freed all memory | ||
1532 | * allocated for its internal data structures. You are responsible for | ||
1533 | * freeing the objects referenced by the XArray. | ||
1534 | * | ||
1535 | * Context: Any context. Takes and releases the xa_lock, interrupt-safe. | ||
1536 | */ | ||
1537 | void xa_destroy(struct xarray *xa) | ||
1538 | { | ||
1539 | XA_STATE(xas, xa, 0); | ||
1540 | unsigned long flags; | ||
1541 | void *entry; | ||
1542 | |||
1543 | xas.xa_node = NULL; | ||
1544 | xas_lock_irqsave(&xas, flags); | ||
1545 | entry = xa_head_locked(xa); | ||
1546 | RCU_INIT_POINTER(xa->xa_head, NULL); | ||
1547 | xas_init_marks(&xas); | ||
1548 | /* lockdep checks we're still holding the lock in xas_free_nodes() */ | ||
1549 | if (xa_is_node(entry)) | ||
1550 | xas_free_nodes(&xas, xa_to_node(entry)); | ||
1551 | xas_unlock_irqrestore(&xas, flags); | ||
1552 | } | ||
1553 | EXPORT_SYMBOL(xa_destroy); | ||
1554 | |||
1527 | #ifdef XA_DEBUG | 1555 | #ifdef XA_DEBUG |
1528 | void xa_dump_node(const struct xa_node *node) | 1556 | void xa_dump_node(const struct xa_node *node) |
1529 | { | 1557 | { |