[dm-devel] [PATCH] dm-cache: destroy migration_cache if cache target registration failed

Shenghui Wang shhuiw at foxmail.com
Sun Oct 7 06:45:41 UTC 2018


Destroy migration_cache if cache target registration failed in
dm_cache_init.

Signed-off-by: Shenghui Wang <shhuiw at foxmail.com>
---
 drivers/md/dm-cache-target.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index e13d991e9fb5..c248667f549d 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -3481,17 +3481,16 @@ static struct target_type cache_target = {
 
 static int __init dm_cache_init(void)
 {
-	int r;
+	int r = -ENOMEM;
 
 	migration_cache = KMEM_CACHE(dm_cache_migration, 0);
-	if (!migration_cache) {
-		dm_unregister_target(&cache_target);
-		return -ENOMEM;
-	}
+	if (!migration_cache)
+		return r;
 
 	r = dm_register_target(&cache_target);
 	if (r) {
 		DMERR("cache target registration failed: %d", r);
+		kmem_cache_destroy(migration_cache);
 		return r;
 	}
 
-- 
2.18.0






More information about the dm-devel mailing list