[PATCH] LIB: add gen_pool_destroy()
authorSteve Wise <swise@opengridcomputing.com>
Mon, 2 Oct 2006 09:17:00 +0000 (02:17 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 2 Oct 2006 14:57:12 +0000 (07:57 -0700)
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>
include/linux/genalloc.h
lib/genalloc.c

index 690c42803d2e7d310e7bd59cbac2abebaa263098..9869ef3674acbfe0f1a8fbad4fd20286c092c3be 100644 (file)
@@ -31,5 +31,6 @@ struct gen_pool_chunk {
 
 extern struct gen_pool *gen_pool_create(int, int);
 extern int gen_pool_add(struct gen_pool *, unsigned long, size_t, int);
+extern void gen_pool_destroy(struct gen_pool *);
 extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
 extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
index 71338b48e88919ab2a668ecf2ff9f1e25a91b0fa..7d16ecabba9620cf0800802d35a4c62f02a62ba2 100644 (file)
@@ -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.