Blob Blame History Raw
From f0ddb83da3cbbf8a1f9087a642c448ff52ee9abd Mon Sep 17 00:00:00 2001
From: Yu Kuai <yukuai3@huawei.com>
Date: Fri, 10 Mar 2023 15:38:55 +0800
Subject: [PATCH] md/raid10: fix memleak of md thread
Git-commit: f0ddb83da3cbbf8a1f9087a642c448ff52ee9abd
Patch-mainline: v6.4-rc1
References: git-fixes

In raid10_run(), if setup_conf() succeed and raid10_run() failed before
setting 'mddev->thread', then in the error path 'conf->thread' is not
freed.

Fix the problem by setting 'mddev->thread' right after setup_conf().

(Coly Li: rebased for Linux v4.12 based SUSE kernel)

Fixes: 43a521238aca ("md-cluster: choose correct label when clustered layout is not supported")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230310073855.1337560-7-yukuai1@huaweicloud.com
Signed-off-by: Coly Li <colyli@suse.de>

---
 drivers/md/raid10.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3799,6 +3799,9 @@ static int raid10_run(struct mddev *mdde
 	if (!conf)
 		goto out;
 
+	mddev->thread = conf->thread;
+	conf->thread = NULL;
+
 	if (mddev_is_clustered(conf->mddev)) {
 		int fc, fo;
 
@@ -3811,9 +3814,6 @@ static int raid10_run(struct mddev *mdde
 		}
 	}
 
-	mddev->thread = conf->thread;
-	conf->thread = NULL;
-
 	chunk_size = mddev->chunk_sectors << 9;
 	if (mddev->queue) {
 		blk_queue_max_discard_sectors(mddev->queue,