Commit 386bc35a authored by Anna Leuschner's avatar Anna Leuschner Committed by Jens Axboe

vfs: fix: don't increase bio_slab_max if krealloc() fails

Without the patch, bio_slab_max, representing bio_slabs capacity, is increased before krealloc() of bio_slabs. If krealloc() fails, bio_slab_max is too high. Fix that by only updating bio_slab_max if krealloc() is successful.
Signed-off-by: default avatarAnna Leuschner <anna.m.leuschner@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 65c77fd9
...@@ -75,6 +75,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) ...@@ -75,6 +75,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
unsigned int sz = sizeof(struct bio) + extra_size; unsigned int sz = sizeof(struct bio) + extra_size;
struct kmem_cache *slab = NULL; struct kmem_cache *slab = NULL;
struct bio_slab *bslab, *new_bio_slabs; struct bio_slab *bslab, *new_bio_slabs;
unsigned int new_bio_slab_max;
unsigned int i, entry = -1; unsigned int i, entry = -1;
mutex_lock(&bio_slab_lock); mutex_lock(&bio_slab_lock);
...@@ -97,12 +98,13 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) ...@@ -97,12 +98,13 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
goto out_unlock; goto out_unlock;
if (bio_slab_nr == bio_slab_max && entry == -1) { if (bio_slab_nr == bio_slab_max && entry == -1) {
bio_slab_max <<= 1; new_bio_slab_max = bio_slab_max << 1;
new_bio_slabs = krealloc(bio_slabs, new_bio_slabs = krealloc(bio_slabs,
bio_slab_max * sizeof(struct bio_slab), new_bio_slab_max * sizeof(struct bio_slab),
GFP_KERNEL); GFP_KERNEL);
if (!new_bio_slabs) if (!new_bio_slabs)
goto out_unlock; goto out_unlock;
bio_slab_max = new_bio_slab_max;
bio_slabs = new_bio_slabs; bio_slabs = new_bio_slabs;
} }
if (entry == -1) if (entry == -1)
......
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