[PATCH 3/3] nbd: add error handling support for add_disk()
From: Luis Chamberlain
Date: Thu Jul 15 2021 - 15:55:05 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/nbd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b7d663736d35..0ecc1e4e16fd 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1730,10 +1730,14 @@ static int nbd_dev_add(int index)
disk->fops = &nbd_fops;
disk->private_data = nbd;
sprintf(disk->disk_name, "nbd%d", index);
- add_disk(disk);
+ err = add_disk(disk);
+ if (err)
+ goto out_err_disk;
nbd_total_devices++;
return index;
+out_err_disk:
+ blk_cleanup_disk(disk);
out_free_idr:
idr_remove(&nbd_index_idr, index);
out_free_tags:
--
2.27.0