summaryrefslogtreecommitdiffstats
path: root/lib/genalloc.c
diff options
context:
space:
mode:
authorSteve Wise <swise@opengridcomputing.com>2006-10-02 11:17:00 +0200
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 16:57:12 +0200
commit322acc96d4bd3debea11cd0160b18bd5d7ff0d73 (patch)
tree230e9c35e0ce4dac5bd1a49085152624045fb616 /lib/genalloc.c
parentpccard_store_cis: fix wrong error handling (diff)
downloadlinux-322acc96d4bd3debea11cd0160b18bd5d7ff0d73.tar.xz
linux-322acc96d4bd3debea11cd0160b18bd5d7ff0d73.zip
[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 <swise@opengridcomputing.com> Cc: Randy Dunlap <rdunlap@xenotime.net> Cc: Dean Nelson <dcn@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib/genalloc.c')
-rw-r--r--lib/genalloc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 71338b48e889..7d16ecabba96 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -71,6 +71,36 @@ 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.
*