aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mempool.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mempool.c')
-rw-r--r--mm/mempool.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mm/mempool.c b/mm/mempool.c
index e209c98c7203..949970db2874 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -113,23 +113,24 @@ EXPORT_SYMBOL(mempool_create_node);
113 * mempool_create(). 113 * mempool_create().
114 * @new_min_nr: the new minimum number of elements guaranteed to be 114 * @new_min_nr: the new minimum number of elements guaranteed to be
115 * allocated for this pool. 115 * allocated for this pool.
116 * @gfp_mask: the usual allocation bitmask.
117 * 116 *
118 * This function shrinks/grows the pool. In the case of growing, 117 * This function shrinks/grows the pool. In the case of growing,
119 * it cannot be guaranteed that the pool will be grown to the new 118 * it cannot be guaranteed that the pool will be grown to the new
120 * size immediately, but new mempool_free() calls will refill it. 119 * size immediately, but new mempool_free() calls will refill it.
120 * This function may sleep.
121 * 121 *
122 * Note, the caller must guarantee that no mempool_destroy is called 122 * Note, the caller must guarantee that no mempool_destroy is called
123 * while this function is running. mempool_alloc() & mempool_free() 123 * while this function is running. mempool_alloc() & mempool_free()
124 * might be called (eg. from IRQ contexts) while this function executes. 124 * might be called (eg. from IRQ contexts) while this function executes.
125 */ 125 */
126int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask) 126int mempool_resize(mempool_t *pool, int new_min_nr)
127{ 127{
128 void *element; 128 void *element;
129 void **new_elements; 129 void **new_elements;
130 unsigned long flags; 130 unsigned long flags;
131 131
132 BUG_ON(new_min_nr <= 0); 132 BUG_ON(new_min_nr <= 0);
133 might_sleep();
133 134
134 spin_lock_irqsave(&pool->lock, flags); 135 spin_lock_irqsave(&pool->lock, flags);
135 if (new_min_nr <= pool->min_nr) { 136 if (new_min_nr <= pool->min_nr) {
@@ -145,7 +146,8 @@ int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask)
145 spin_unlock_irqrestore(&pool->lock, flags); 146 spin_unlock_irqrestore(&pool->lock, flags);
146 147
147 /* Grow the pool */ 148 /* Grow the pool */
148 new_elements = kmalloc(new_min_nr * sizeof(*new_elements), gfp_mask); 149 new_elements = kmalloc_array(new_min_nr, sizeof(*new_elements),
150 GFP_KERNEL);
149 if (!new_elements) 151 if (!new_elements)
150 return -ENOMEM; 152 return -ENOMEM;
151 153
@@ -164,7 +166,7 @@ int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask)
164 166
165 while (pool->curr_nr < pool->min_nr) { 167 while (pool->curr_nr < pool->min_nr) {
166 spin_unlock_irqrestore(&pool->lock, flags); 168 spin_unlock_irqrestore(&pool->lock, flags);
167 element = pool->alloc(gfp_mask, pool->pool_data); 169 element = pool->alloc(GFP_KERNEL, pool->pool_data);
168 if (!element) 170 if (!element)
169 goto out; 171 goto out;
170 spin_lock_irqsave(&pool->lock, flags); 172 spin_lock_irqsave(&pool->lock, flags);