Skip to contentSkip to conversation

dm-cache: destroy migration_cache if cache target registration failed

PATCH New Shenghui Wang 1 participant 1 message Oct 7, 2018 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-cache: destroy migration_cache if cache target registration failed

Destroy migration_cache if cache target registration failed in dm_cache_init.

---
 drivers/md/dm-cache-target.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/dm-cache-target.c +4 -5
index e13d991e9fb5..c248667f549d 100644
@@ -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;
 	}
 
Signature · 1 line
2.18.0