From 322acc96d4bd3debea11cd0160b18bd5d7ff0d73 Mon Sep 17 00:00:00 2001 From: Steve Wise Date: Mon, 2 Oct 2006 02:17:00 -0700 Subject: [PATCH] LIB: add gen_pool_destroy() Modules using the genpool allocator need to be able to destroy the data structure when unloading. Signed-off-by: Steve Wise Cc: Randy Dunlap Cc: Dean Nelson Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/genalloc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/genalloc.c') diff --git a/lib/genalloc.c b/lib/genalloc.c index 71338b48e88..7d16ecabba9 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -70,6 +70,36 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, EXPORT_SYMBOL(gen_pool_add); +/* + * Destroy a memory pool. Verifies that there are no outstanding allocations. + * + * @pool: pool to destroy + */ +void gen_pool_destroy(struct gen_pool *pool) +{ + struct list_head *_chunk, *_next_chunk; + struct gen_pool_chunk *chunk; + int order = pool->min_alloc_order; + int bit, end_bit; + + + write_lock(&pool->lock); + list_for_each_safe(_chunk, _next_chunk, &pool->chunks) { + chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk); + list_del(&chunk->next_chunk); + + end_bit = (chunk->end_addr - chunk->start_addr) >> order; + bit = find_next_bit(chunk->bits, end_bit, 0); + BUG_ON(bit < end_bit); + + kfree(chunk); + } + kfree(pool); + return; +} +EXPORT_SYMBOL(gen_pool_destroy); + + /* * Allocate the requested number of bytes from the specified pool. * Uses a first-fit algorithm. -- cgit v1.2.3