When fail to create new cache in bio_find_or_create_slab(),
we should not increase bio_slab_nr because it will cause
referring uninitilized data in subsequent search.

Signed-off-by: Chengguang Xu <[email protected]>
---
 block/bio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index 4db1008309ed..8081906f5d01 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -109,7 +109,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned 
int extra_size)
                bio_slabs = new_bio_slabs;
        }
        if (entry == -1)
-               entry = bio_slab_nr++;
+               entry = bio_slab_nr;
 
        bslab = &bio_slabs[entry];
 
@@ -122,6 +122,10 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned 
int extra_size)
        bslab->slab = slab;
        bslab->slab_ref = 1;
        bslab->slab_size = sz;
+
+       if (entry == bio_slab_nr)
+               bio_slab_nr++;
+
 out_unlock:
        mutex_unlock(&bio_slab_lock);
        return slab;
-- 
2.20.1

Reply via email to