Skip to content

Commit c9ac2ac

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid10: fix memleak for 'conf->bio_split'
In the error path of raid10_run(), 'conf' need be freed, however, 'conf->bio_split' is missed and memory will be leaked. Since there are 3 places to free 'conf', factor out a helper to fix the problem. Fixes: fc9977d ("md/raid10: simplify the splitting of requests.") Signed-off-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230310073855.1337560-6-yukuai1@huaweicloud.com
1 parent 26208a7 commit c9ac2ac

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

drivers/md/raid10.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,6 +4017,20 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)
40174017
return nc*fc;
40184018
}
40194019

4020+
static void raid10_free_conf(struct r10conf *conf)
4021+
{
4022+
if (!conf)
4023+
return;
4024+
4025+
mempool_exit(&conf->r10bio_pool);
4026+
kfree(conf->mirrors);
4027+
kfree(conf->mirrors_old);
4028+
kfree(conf->mirrors_new);
4029+
safe_put_page(conf->tmppage);
4030+
bioset_exit(&conf->bio_split);
4031+
kfree(conf);
4032+
}
4033+
40204034
static struct r10conf *setup_conf(struct mddev *mddev)
40214035
{
40224036
struct r10conf *conf = NULL;
@@ -4099,13 +4113,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
40994113
return conf;
41004114

41014115
out:
4102-
if (conf) {
4103-
mempool_exit(&conf->r10bio_pool);
4104-
kfree(conf->mirrors);
4105-
safe_put_page(conf->tmppage);
4106-
bioset_exit(&conf->bio_split);
4107-
kfree(conf);
4108-
}
4116+
raid10_free_conf(conf);
41094117
return ERR_PTR(err);
41104118
}
41114119

@@ -4296,26 +4304,15 @@ static int raid10_run(struct mddev *mddev)
42964304

42974305
out_free_conf:
42984306
md_unregister_thread(&mddev->thread);
4299-
mempool_exit(&conf->r10bio_pool);
4300-
safe_put_page(conf->tmppage);
4301-
kfree(conf->mirrors);
4302-
kfree(conf);
4307+
raid10_free_conf(conf);
43034308
mddev->private = NULL;
43044309
out:
43054310
return -EIO;
43064311
}
43074312

43084313
static void raid10_free(struct mddev *mddev, void *priv)
43094314
{
4310-
struct r10conf *conf = priv;
4311-
4312-
mempool_exit(&conf->r10bio_pool);
4313-
safe_put_page(conf->tmppage);
4314-
kfree(conf->mirrors);
4315-
kfree(conf->mirrors_old);
4316-
kfree(conf->mirrors_new);
4317-
bioset_exit(&conf->bio_split);
4318-
kfree(conf);
4315+
raid10_free_conf(priv);
43194316
}
43204317

43214318
static void raid10_quiesce(struct mddev *mddev, int quiesce)

0 commit comments

Comments
 (0)