Skip to contentSkip to conversation

dm mpath: simplify failure path of dm_miltipath_init()

PATCH New Johannes Thumshirn 1 participant 1 message Jan 11, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm mpath: simplify failure path of dm_miltipath_init()

simplify failure path of dm_miltipath_init(). Currently the cleanup of all error cases are open-coded. Introduce a common exit path and lables.

---
 drivers/md/dm-mpath.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/md/dm-mpath.c +15 -9
index 7b6b0f0..5cc3438 100644
@@ -1694,16 +1694,15 @@ static int __init dm_multipath_init(void)
 	r = dm_register_target(&multipath_target);
 	if (r < 0) {
 		DMERR("register failed %d", r);
-		kmem_cache_destroy(_mpio_cache);
-		return -EINVAL;
+		r = -EINVAL;
+		goto out_mpio_cache;
 	}
 
 	kmultipathd = alloc_workqueue("kmpathd", WQ_MEM_RECLAIM, 0);
 	if (!kmultipathd) {
 		DMERR("failed to create workqueue kmpathd");
-		dm_unregister_target(&multipath_target);
-		kmem_cache_destroy(_mpio_cache);
-		return -ENOMEM;
+		r = -ENOMEM;
+		goto out_kmultipathd;
 	}
 
 	/*
@@ -1716,16 +1715,23 @@ static int __init dm_multipath_init(void)
 						  WQ_MEM_RECLAIM);
 	if (!kmpath_handlerd) {
 		DMERR("failed to create workqueue kmpath_handlerd");
-		destroy_workqueue(kmultipathd);
-		dm_unregister_target(&multipath_target);
-		kmem_cache_destroy(_mpio_cache);
-		return -ENOMEM;
+		r = -ENOMEM;
+		goto out_kmpath_handlerd;
 	}
 
 	DMINFO("version %u.%u.%u loaded",
 	       multipath_target.version[0], multipath_target.version[1],
 	       multipath_target.version[2]);
 
+	return 0;
+
+out_kmpath_handlerd:
+	destroy_workqueue(kmultipathd);
+out_kmultipathd:
+	dm_unregister_target(&multipath_target);
+out_mpio_cache:
+	kmem_cache_destroy(_mpio_cache);
+
 	return r;
 }
 
Signature · 1 line
2.1.0