Skip to content

Commit

Permalink
[PATCH] LIB: add gen_pool_destroy()
Browse files Browse the repository at this point in the history
Modules using the genpool allocator need to be able to destroy the data
structure when unloading.

Signed-off-by: Steve Wise <[email protected]>
Cc: Randy Dunlap <[email protected]>
Cc: Dean Nelson <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Steve Wise authored and Linus Torvalds committed Oct 2, 2006
1 parent d834c16 commit 322acc9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/genalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
30 changes: 30 additions & 0 deletions lib/genalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 322acc9

Please sign in to comment.