aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mempool.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-01-10 18:08:26 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-10 19:30:45 -0500
commit0565d317768cc66b13e37184f29d9f270c2886dc (patch)
tree9618e46da0eac37472cde829d9574a98a1d28bbb /mm/mempool.c
parent5b990546e33477c34ee6fbc20fad6584386b46c3 (diff)
mempool: drop unnecessary and incorrect BUG_ON() from mempool_destroy()
mempool_destroy() is a thin wrapper around free_pool(). The only thing it adds is BUG_ON(pool->curr_nr != pool->min_nr). The intention seems to be to enforce that all allocated elements are freed; however, the BUG_ON() can't achieve that (it doesn't know anything about objects above min_nr) and incorrect as mempool_resize() is allowed to leave the pool extended but not filled. Furthermore, panicking is way worse than any memory leak and there are better debug tools to track memory leaks. Drop the BUG_ON() from mempool_destory() and as that leaves the function identical to free_pool(), replace it. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mempool.c')
-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().