Skip to content

Commit 322acc9

Browse files
Steve WiseLinus Torvalds
authored andcommitted
[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>
1 parent d834c16 commit 322acc9

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎include/linux/genalloc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ struct gen_pool_chunk {
3131

3232
extern struct gen_pool *gen_pool_create(int, int);
3333
extern int gen_pool_add(struct gen_pool *, unsigned long, size_t, int);
34+
extern void gen_pool_destroy(struct gen_pool *);
3435
extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
3536
extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);

‎lib/genalloc.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size,
7070
EXPORT_SYMBOL(gen_pool_add);
7171

7272

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+
73103
/*
74104
* Allocate the requested number of bytes from the specified pool.
75105
* Uses a first-fit algorithm.

0 commit comments

Comments
 (0)