diff options
author | Luis Chamberlain <mcgrof@kernel.org> | 2021-10-15 16:52:07 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-10-30 11:07:40 -0600 |
commit | e1528830bd4ebf435d91c154e309e6e028336210 (patch) | |
tree | 974ab70848c421f3247c4dce1abe418e2bcf603d /drivers/block/brd.c | |
parent | 3c30883acab1d20ecbd3c48dc12b147b51548742 (diff) |
block/brd: add error handling support for add_disk()
We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20211015235219.2191207-2-mcgrof@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/brd.c')
-rw-r--r-- | drivers/block/brd.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/block/brd.c b/drivers/block/brd.c index aa0472718dce..a896ee175d86 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -370,6 +370,7 @@ static int brd_alloc(int i) struct brd_device *brd; struct gendisk *disk; char buf[DISK_NAME_LEN]; + int err = -ENOMEM; mutex_lock(&brd_devices_mutex); list_for_each_entry(brd, &brd_devices, brd_list) { @@ -420,16 +421,20 @@ static int brd_alloc(int i) /* Tell the block layer that this is not a rotational device */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); - add_disk(disk); + err = add_disk(disk); + if (err) + goto out_cleanup_disk; return 0; +out_cleanup_disk: + blk_cleanup_disk(disk); out_free_dev: mutex_lock(&brd_devices_mutex); list_del(&brd->brd_list); mutex_unlock(&brd_devices_mutex); kfree(brd); - return -ENOMEM; + return err; } static void brd_probe(dev_t dev) |