Skip to content

Commit 224b068

Browse files
Christoph Hellwigaxboe
authored andcommitted
bcache: add proper error unwinding in bcache_device_init
Except for the IDA none of the allocations in bcache_device_init is unwound on error, fix that. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Coly Li <colyli@suse.de> Link: https://lore.kernel.org/r/20210809064028.1198327-7-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4f9e14a commit 224b068

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎drivers/md/bcache/super.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -931,20 +931,20 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
931931
n = BITS_TO_LONGS(d->nr_stripes) * sizeof(unsigned long);
932932
d->full_dirty_stripes = kvzalloc(n, GFP_KERNEL);
933933
if (!d->full_dirty_stripes)
934-
return -ENOMEM;
934+
goto out_free_stripe_sectors_dirty;
935935

936936
idx = ida_simple_get(&bcache_device_idx, 0,
937937
BCACHE_DEVICE_IDX_MAX, GFP_KERNEL);
938938
if (idx < 0)
939-
return idx;
939+
goto out_free_full_dirty_stripes;
940940

941941
if (bioset_init(&d->bio_split, 4, offsetof(struct bbio, bio),
942942
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
943-
goto err;
943+
goto out_ida_remove;
944944

945945
d->disk = blk_alloc_disk(NUMA_NO_NODE);
946946
if (!d->disk)
947-
goto err;
947+
goto out_bioset_exit;
948948

949949
set_capacity(d->disk, sectors);
950950
snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", idx);
@@ -987,8 +987,14 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
987987

988988
return 0;
989989

990-
err:
990+
out_bioset_exit:
991+
bioset_exit(&d->bio_split);
992+
out_ida_remove:
991993
ida_simple_remove(&bcache_device_idx, idx);
994+
out_free_full_dirty_stripes:
995+
kvfree(d->full_dirty_stripes);
996+
out_free_stripe_sectors_dirty:
997+
kvfree(d->stripe_sectors_dirty);
992998
return -ENOMEM;
993999

9941000
}

0 commit comments

Comments
 (0)