summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-06-21 15:36:45 -0400
committerMatthew Wilcox <willy@infradead.org>2018-08-21 23:49:31 -0400
commit50d97d50715a8664f6bddc18211279cd74b8c3bf (patch)
treecef02f64a84dc6e0132be30ab0bccef1496ae85f /lib
parent76f070b4135563165c523ab560056b7a9353e2f2 (diff)
ida: Lock the IDA in ida_destroy
The user has no need to handle locking between ida_simple_get() and ida_simple_remove(). They shouldn't be forced to think about whether ida_destroy() might be called at the same time as any of their other IDA manipulation calls. Improve the documnetation while I'm in here. Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/idr.c b/lib/idr.c
index ed9c169c12bd..352c6160e2e0 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -523,25 +523,30 @@ void ida_remove(struct ida *ida, int id)
523EXPORT_SYMBOL(ida_remove); 523EXPORT_SYMBOL(ida_remove);
524 524
525/** 525/**
526 * ida_destroy - Free the contents of an ida 526 * ida_destroy() - Free all IDs.
527 * @ida: ida handle 527 * @ida: IDA handle.
528 *
529 * Calling this function frees all IDs and releases all resources used
530 * by an IDA. When this call returns, the IDA is empty and can be reused
531 * or freed. If the IDA is already empty, there is no need to call this
532 * function.
528 * 533 *
529 * Calling this function releases all resources associated with an IDA. When 534 * Context: Any context.
530 * this call returns, the IDA is empty and can be reused or freed. The caller
531 * should not allow ida_remove() or ida_get_new_above() to be called at the
532 * same time.
533 */ 535 */
534void ida_destroy(struct ida *ida) 536void ida_destroy(struct ida *ida)
535{ 537{
538 unsigned long flags;
536 struct radix_tree_iter iter; 539 struct radix_tree_iter iter;
537 void __rcu **slot; 540 void __rcu **slot;
538 541
542 xa_lock_irqsave(&ida->ida_rt, flags);
539 radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) { 543 radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) {
540 struct ida_bitmap *bitmap = rcu_dereference_raw(*slot); 544 struct ida_bitmap *bitmap = rcu_dereference_raw(*slot);
541 if (!radix_tree_exception(bitmap)) 545 if (!radix_tree_exception(bitmap))
542 kfree(bitmap); 546 kfree(bitmap);
543 radix_tree_iter_delete(&ida->ida_rt, &iter, slot); 547 radix_tree_iter_delete(&ida->ida_rt, &iter, slot);
544 } 548 }
549 xa_unlock_irqrestore(&ida->ida_rt, flags);
545} 550}
546EXPORT_SYMBOL(ida_destroy); 551EXPORT_SYMBOL(ida_destroy);
547 552