aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid1.c
diff options
context:
space:
mode:
authorZheng Qixing <[email protected]>2025-02-15 02:01:37 +0000
committerYu Kuai <[email protected]>2025-02-15 11:45:58 +0000
commit5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35 (patch)
tree9b6c78b4bb10bd6339b47efa8c49fb81502d021c /drivers/md/raid1.c
parentmd: ensure resync is prioritized over recovery (diff)
downloadkernel-5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35.tar.gz
kernel-5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35.zip
md/raid1: fix memory leak in raid1_run() if no active rdev
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: Zheng Qixing <[email protected]> Link: https://lore.kernel.org/linux-raid/[email protected] Singed-off-by: Yu Kuai <[email protected]>
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r--drivers/md/raid1.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 9d57a88dbd26..a87eb9a3b016 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -45,6 +45,7 @@
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 RAID_1_10_NAME "raid1"
#include "raid1-10.c"
@@ -3258,8 +3259,11 @@ static int raid1_run(struct mddev *mddev)
if (!mddev_is_dm(mddev)) {
ret = raid1_set_limits(mddev);
- if (ret)
+ if (ret) {
+ if (!mddev->private)
+ raid1_free(mddev, conf);
return ret;
+ }
}
mddev->degraded = 0;
@@ -3273,6 +3277,8 @@ static int raid1_run(struct mddev *mddev)
*/
if (conf->raid_disks - mddev->degraded < 1) {
md_unregister_thread(mddev, &conf->thread);
+ if (!mddev->private)
+ raid1_free(mddev, conf);
return -EINVAL;
}