aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/mempool.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/mm/mempool.c b/mm/mempool.c
index 11f0d0a5e0f8..e3a802a0cea0 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -27,7 +27,15 @@ static void *remove_element(mempool_t *pool)
27 return pool->elements[--pool->curr_nr]; 27 return pool->elements[--pool->curr_nr];
28} 28}
29 29
30static void free_pool(mempool_t *pool) 30/**
31 * mempool_destroy - deallocate a memory pool
32 * @pool: pointer to the memory pool which was allocated via
33 * mempool_create().
34 *
35 * Free all reserved elements in @pool and @pool itself. This function
36 * only sleeps if the free_fn() function sleeps.
37 */
38void mempool_destroy(mempool_t *pool)
31{ 39{
32 while (pool->curr_nr) { 40 while (pool->curr_nr) {
33 void *element = remove_element(pool); 41 void *element = remove_element(pool);
@@ -36,6 +44,7 @@ static void free_pool(mempool_t *pool)
36 kfree(pool->elements); 44 kfree(pool->elements);
37 kfree(pool); 45 kfree(pool);
38} 46}
47EXPORT_SYMBOL(mempool_destroy);
39 48
40/** 49/**
41 * mempool_create - create a memory pool 50 * mempool_create - create a memory pool
@@ -86,7 +95,7 @@ mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
86 95
87 element = pool->alloc(GFP_KERNEL, pool->pool_data); 96 element = pool->alloc(GFP_KERNEL, pool->pool_data);
88 if (unlikely(!element)) { 97 if (unlikely(!element)) {
89 free_pool(pool); 98 mempool_destroy(pool);
90 return NULL; 99 return NULL;
91 } 100 }
92 add_element(pool, element); 101 add_element(pool, element);
@@ -172,23 +181,6 @@ out:
172EXPORT_SYMBOL(mempool_resize); 181EXPORT_SYMBOL(mempool_resize);
173 182
174/** 183/**
175 * mempool_destroy - deallocate a memory pool
176 * @pool: pointer to the memory pool which was allocated via
177 * mempool_create().
178 *
179 * this function only sleeps if the free_fn() function sleeps. The caller
180 * has to guarantee that all elements have been returned to the pool (ie:
181 * freed) prior to calling mempool_destroy().
182 */
183void mempool_destroy(mempool_t *pool)
184{
185 /* Check for outstanding elements */
186 BUG_ON(pool->curr_nr != pool->min_nr);
187 free_pool(pool);
188}
189EXPORT_SYMBOL(mempool_destroy);
190
191/**
192 * mempool_alloc - allocate an element from a specific memory pool 184 * mempool_alloc - allocate an element from a specific memory pool
193 * @pool: pointer to the memory pool which was allocated via 185 * @pool: pointer to the memory pool which was allocated via
194 * mempool_create(). 186 * mempool_create().