[PATCH v4 4/6] dm: add add_disk() error handling

From: Luis Chamberlain
Date: Mon Sep 27 2021 - 18:00:46 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.

There are two calls to dm_setup_md_queue() which can fail then,
one on dm_early_create() and we can easily see that the error path
there calls dm_destroy in the error path. The other use case is on
the ioctl table_load case. If that fails userspace needs to call
the DM_DEV_REMOVE_CMD to cleanup the state - similar to any other
failure.

Reviewed-by: Hannes Reinecke <hare@xxxxxxx>
Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
---
drivers/md/dm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a011d09cb0fa..b83aab8507c2 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2083,7 +2083,9 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
if (r)
return r;

- add_disk(md->disk);
+ r = add_disk(md->disk);
+ if (r)
+ return r;

r = dm_sysfs_init(md);
if (r) {
--
2.30.2