Skip to content
/ linux Public

Commit ec10e3d

Browse files
GoodLuck612gregkh
authored andcommitted
md/raid1: fix memory leak in raid1_run()
[ Upstream commit 6abc7d5 ] raid1_run() calls setup_conf() which registers a thread via md_register_thread(). If raid1_set_limits() fails, the previously registered thread is not unregistered, resulting in a memory leak of the md_thread structure and the thread resource itself. Add md_unregister_thread() to the error path to properly cleanup the thread, which aligns with the error handling logic of other paths in this function. Compile tested only. Issue found using a prototype static analysis tool and code review. Link: https://lore.kernel.org/linux-raid/20260126071533.606263-1-zilin@seu.edu.cn Fixes: 97894f7 ("md/raid1: use the atomic queue limit update APIs") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Reviewed-by: Li Nan <linan122@huawei.com> Signed-off-by: Yu Kuai <yukuai@fnnas.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 02455f6 commit ec10e3d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/md/raid1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,7 @@ static int raid1_run(struct mddev *mddev)
32533253
if (!mddev_is_dm(mddev)) {
32543254
ret = raid1_set_limits(mddev);
32553255
if (ret) {
3256+
md_unregister_thread(mddev, &conf->thread);
32563257
if (!mddev->private)
32573258
raid1_free(mddev, conf);
32583259
return ret;

0 commit comments

Comments
 (0)