[RFC 11/12] block/brd: add error handling support for add_disk()

From: Luis Chamberlain
Date: Thu Jul 15 2021 - 17:00:35 EST


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@xxxxxxxxxx>
---
drivers/block/brd.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 95694113e38e..ca017ca315c5 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -375,6 +375,7 @@ static int brd_alloc(int i)
struct brd_device *brd;
struct gendisk *disk;
char buf[DISK_NAME_LEN];
+ int err = -ENOMEM;

brd = kzalloc(sizeof(*brd), GFP_KERNEL);
if (!brd)
@@ -413,14 +414,19 @@ 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;
+
list_add_tail(&brd->brd_list, &brd_devices);

return 0;

+out_cleanup_disk:
+ blk_cleanup_disk(disk);
out_free_dev:
kfree(brd);
- return -ENOMEM;
+ return err;
}

static void brd_probe(dev_t dev)
--
2.27.0