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,
}
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
* @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)
if (!element)
goto out;
spin_lock_irqsave(&pool->lock, flags);
if (pool->curr_nr < pool->min_nr)
if (pool->curr_nr < pool->min_nr) {
add_element(pool, element);
else
kfree(element); /* Raced */
} else {
spin_unlock_irqrestore(&pool->lock, flags);
pool->free(element, pool->pool_data); /* Raced */
spin_lock_irqsave(&pool->lock, flags);
}
}
out_unlock:
spin_unlock_irqrestore(&pool->lock, flags);
out:
return 0;
}
EXPORT_SYMBOL(mempool_resize);
#endif
/**
* mempool_destroy - deallocate a memory pool
......@@ -169,6 +180,7 @@ void mempool_destroy(mempool_t *pool)
BUG(); /* There were outstanding elements */
free_pool(pool);
}
EXPORT_SYMBOL(mempool_destroy);
/**
* mempool_alloc - allocate an element from a specific memory pool
......@@ -230,6 +242,7 @@ void * mempool_alloc(mempool_t *pool, int gfp_mask)
goto repeat_alloc;
}
EXPORT_SYMBOL(mempool_alloc);
/**
* mempool_free - return an element to the pool.
......@@ -255,6 +268,7 @@ void mempool_free(void *element, mempool_t *pool)
}
pool->free(element, pool->pool_data);
}
EXPORT_SYMBOL(mempool_free);
/*
* A commonly used alloc and free fn.
......@@ -264,17 +278,11 @@ void *mempool_alloc_slab(int gfp_mask, void *pool_data)
kmem_cache_t *mem = (kmem_cache_t *) pool_data;
return kmem_cache_alloc(mem, gfp_mask);
}
EXPORT_SYMBOL(mempool_alloc_slab);
void mempool_free_slab(void *element, void *pool_data)
{
kmem_cache_t *mem = (kmem_cache_t *) pool_data;
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);
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