Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Steve Wise and committed by
Linus Torvalds
322acc96 d834c165

+31
+1
include/linux/genalloc.h
··· 31 31 32 32 extern struct gen_pool *gen_pool_create(int, int); 33 33 extern int gen_pool_add(struct gen_pool *, unsigned long, size_t, int); 34 + extern void gen_pool_destroy(struct gen_pool *); 34 35 extern unsigned long gen_pool_alloc(struct gen_pool *, size_t); 35 36 extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
+30
lib/genalloc.c
··· 71 71 72 72 73 73 /* 74 + * Destroy a memory pool. Verifies that there are no outstanding allocations. 75 + * 76 + * @pool: pool to destroy 77 + */ 78 + void gen_pool_destroy(struct gen_pool *pool) 79 + { 80 + struct list_head *_chunk, *_next_chunk; 81 + struct gen_pool_chunk *chunk; 82 + int order = pool->min_alloc_order; 83 + int bit, end_bit; 84 + 85 + 86 + write_lock(&pool->lock); 87 + list_for_each_safe(_chunk, _next_chunk, &pool->chunks) { 88 + chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk); 89 + list_del(&chunk->next_chunk); 90 + 91 + end_bit = (chunk->end_addr - chunk->start_addr) >> order; 92 + bit = find_next_bit(chunk->bits, end_bit, 0); 93 + BUG_ON(bit < end_bit); 94 + 95 + kfree(chunk); 96 + } 97 + kfree(pool); 98 + return; 99 + } 100 + EXPORT_SYMBOL(gen_pool_destroy); 101 + 102 + 103 + /* 74 104 * Allocate the requested number of bytes from the specified pool. 75 105 * Uses a first-fit algorithm. 76 106 *