Skip to content

Commit cf13537

Browse files
Christoph Hellwiggregkh
authored andcommitted
bcache: add proper error unwinding in bcache_device_init
[ Upstream commit 224b068 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 48aa6e4 commit cf13537

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
@@ -934,20 +934,20 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
934934
n = BITS_TO_LONGS(d->nr_stripes) * sizeof(unsigned long);
935935
d->full_dirty_stripes = kvzalloc(n, GFP_KERNEL);
936936
if (!d->full_dirty_stripes)
937-
return -ENOMEM;
937+
goto out_free_stripe_sectors_dirty;
938938

939939
idx = ida_simple_get(&bcache_device_idx, 0,
940940
BCACHE_DEVICE_IDX_MAX, GFP_KERNEL);
941941
if (idx < 0)
942-
return idx;
942+
goto out_free_full_dirty_stripes;
943943

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

948948
d->disk = alloc_disk(BCACHE_MINORS);
949949
if (!d->disk)
950-
goto err;
950+
goto out_bioset_exit;
951951

952952
set_capacity(d->disk, sectors);
953953
snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", idx);
@@ -993,8 +993,14 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
993993

994994
return 0;
995995

996-
err:
996+
out_bioset_exit:
997+
bioset_exit(&d->bio_split);
998+
out_ida_remove:
997999
ida_simple_remove(&bcache_device_idx, idx);
1000+
out_free_full_dirty_stripes:
1001+
kvfree(d->full_dirty_stripes);
1002+
out_free_stripe_sectors_dirty:
1003+
kvfree(d->stripe_sectors_dirty);
9981004
return -ENOMEM;
9991005

10001006
}

0 commit comments

Comments
 (0)