Commit 14eaaf8f authored by Zheng Qixing's avatar Zheng Qixing
Browse files

md/raid1: fix memory leak in raid1_run() if no active rdev

maillist inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBKXOB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux.git/commit/?h=md-6.15&id=5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35



----------------------

When `raid1_set_limits()` fails or when the array has no active
`rdev`, the allocated memory for `conf` is not properly freed.

Add raid1_free() call to properly free the conf in error path.

Fixes: 799af947ed13 ("md/raid1: don't free conf on raid0_run failure")
Signed-off-by: default avatarZheng Qixing <zhengqixing@huawei.com>
Conflicts:
	drivers/md/raid1.c
[Context conflicts.]
Signed-off-by: default avatarZheng Qixing <zhengqixing@huawei.com>
parent df354167
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ static int max_queued_requests = 1024;

static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
static void raid1_free(struct mddev *mddev, void *priv);

#define raid1_log(md, fmt, args...)				\
	do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0)
@@ -3148,6 +3149,8 @@ static int raid1_run(struct mddev *mddev)
	 */
	if (conf->raid_disks - mddev->degraded < 1) {
		md_unregister_thread(&conf->thread);
		if (!mddev->private)
			raid1_free(mddev, conf);
		return -EINVAL;
	}