diff mbox series

[1/2] brd: add error handling support for add_disk()

Message ID 1636014799-20156-2-git-send-email-wubo40@huawei.com (mailing list archive)
State New, archived
Headers show
Series add error handling support for add_disk() | expand

Commit Message

Wu Bo Nov. 4, 2021, 8:33 a.m. UTC
We never checked for errors on add_disk() as this function
returned void. Now that is fixed. 

So add error handling support for add_disk().

Signed-off-by: Wu Bo <wubo40@huawei.com>
---
 drivers/block/brd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index aa04727..34a0d9c 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;
 
 	mutex_lock(&brd_devices_mutex);
 	list_for_each_entry(brd, &brd_devices, brd_list) {
@@ -420,10 +421,14 @@  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);