Commit 6dec67d3 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] mempool_resize fix

David Brownell noticed this.  mempool_resize() is calling kfree on a rare
path when it should be calling the pool's free function.

The patch fixes that up, and then disables mempool_resize() compilation - it
has no callers at present.
parent c3ed96a7
...@@ -87,7 +87,13 @@ mempool_t * mempool_create(int min_nr, mempool_alloc_t *alloc_fn, ...@@ -87,7 +87,13 @@ mempool_t * mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
} }
return pool; return pool;
} }
EXPORT_SYMBOL(mempool_create);
/*
* mempool_resize is disabled for now, because it has no callers. Feel free
* to turn it back on if needed.
*/
#if 0
/** /**
* mempool_resize - resize an existing memory pool * mempool_resize - resize an existing memory pool
* @pool: pointer to the memory pool which was allocated via * @pool: pointer to the memory pool which was allocated via
...@@ -143,16 +149,21 @@ int mempool_resize(mempool_t *pool, int new_min_nr, int gfp_mask) ...@@ -143,16 +149,21 @@ int mempool_resize(mempool_t *pool, int new_min_nr, int gfp_mask)
if (!element) if (!element)
goto out; goto out;
spin_lock_irqsave(&pool->lock, flags); spin_lock_irqsave(&pool->lock, flags);
if (pool->curr_nr < pool->min_nr) if (pool->curr_nr < pool->min_nr) {
add_element(pool, element); add_element(pool, element);
else } else {
kfree(element); /* Raced */ spin_unlock_irqrestore(&pool->lock, flags);
pool->free(element, pool->pool_data); /* Raced */
spin_lock_irqsave(&pool->lock, flags);
}
} }
out_unlock: out_unlock:
spin_unlock_irqrestore(&pool->lock, flags); spin_unlock_irqrestore(&pool->lock, flags);
out: out:
return 0; return 0;
} }
EXPORT_SYMBOL(mempool_resize);
#endif
/** /**
* mempool_destroy - deallocate a memory pool * mempool_destroy - deallocate a memory pool
...@@ -169,6 +180,7 @@ void mempool_destroy(mempool_t *pool) ...@@ -169,6 +180,7 @@ void mempool_destroy(mempool_t *pool)
BUG(); /* There were outstanding elements */ BUG(); /* There were outstanding elements */
free_pool(pool); free_pool(pool);
} }
EXPORT_SYMBOL(mempool_destroy);
/** /**
* mempool_alloc - allocate an element from a specific memory pool * mempool_alloc - allocate an element from a specific memory pool
...@@ -230,6 +242,7 @@ void * mempool_alloc(mempool_t *pool, int gfp_mask) ...@@ -230,6 +242,7 @@ void * mempool_alloc(mempool_t *pool, int gfp_mask)
goto repeat_alloc; goto repeat_alloc;
} }
EXPORT_SYMBOL(mempool_alloc);
/** /**
* mempool_free - return an element to the pool. * mempool_free - return an element to the pool.
...@@ -255,6 +268,7 @@ void mempool_free(void *element, mempool_t *pool) ...@@ -255,6 +268,7 @@ void mempool_free(void *element, mempool_t *pool)
} }
pool->free(element, pool->pool_data); pool->free(element, pool->pool_data);
} }
EXPORT_SYMBOL(mempool_free);
/* /*
* A commonly used alloc and free fn. * A commonly used alloc and free fn.
...@@ -264,17 +278,11 @@ void *mempool_alloc_slab(int gfp_mask, void *pool_data) ...@@ -264,17 +278,11 @@ void *mempool_alloc_slab(int gfp_mask, void *pool_data)
kmem_cache_t *mem = (kmem_cache_t *) pool_data; kmem_cache_t *mem = (kmem_cache_t *) pool_data;
return kmem_cache_alloc(mem, gfp_mask); return kmem_cache_alloc(mem, gfp_mask);
} }
EXPORT_SYMBOL(mempool_alloc_slab);
void mempool_free_slab(void *element, void *pool_data) void mempool_free_slab(void *element, void *pool_data)
{ {
kmem_cache_t *mem = (kmem_cache_t *) pool_data; kmem_cache_t *mem = (kmem_cache_t *) pool_data;
kmem_cache_free(mem, element); kmem_cache_free(mem, element);
} }
EXPORT_SYMBOL(mempool_create);
EXPORT_SYMBOL(mempool_resize);
EXPORT_SYMBOL(mempool_destroy);
EXPORT_SYMBOL(mempool_alloc);
EXPORT_SYMBOL(mempool_free);
EXPORT_SYMBOL(mempool_alloc_slab);
EXPORT_SYMBOL(mempool_free_slab); EXPORT_SYMBOL(mempool_free_slab);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment