提交 34cdb051 编写于 作者: Y Yu Kuai 提交者: Jialin Zhang

md/raid10: fix memleak for 'conf->bio_split'

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6L4UU
CVE: NA

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

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: fc9977dd ("md/raid10: simplify the splitting of requests.")
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 641a35c3
...@@ -3624,6 +3624,20 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new) ...@@ -3624,6 +3624,20 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)
return nc*fc; return nc*fc;
} }
static void raid10_free_conf(struct r10conf *conf)
{
if (!conf)
return;
mempool_exit(&conf->r10bio_pool);
kfree(conf->mirrors);
kfree(conf->mirrors_old);
kfree(conf->mirrors_new);
safe_put_page(conf->tmppage);
bioset_exit(&conf->bio_split);
kfree(conf);
}
static struct r10conf *setup_conf(struct mddev *mddev) static struct r10conf *setup_conf(struct mddev *mddev)
{ {
struct r10conf *conf = NULL; struct r10conf *conf = NULL;
...@@ -3706,13 +3720,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) ...@@ -3706,13 +3720,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
return conf; return conf;
out: out:
if (conf) { raid10_free_conf(conf);
mempool_exit(&conf->r10bio_pool);
kfree(conf->mirrors);
safe_put_page(conf->tmppage);
bioset_exit(&conf->bio_split);
kfree(conf);
}
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -3918,10 +3926,7 @@ static int raid10_run(struct mddev *mddev) ...@@ -3918,10 +3926,7 @@ static int raid10_run(struct mddev *mddev)
out_free_conf: out_free_conf:
md_unregister_thread(&mddev->thread); md_unregister_thread(&mddev->thread);
mempool_exit(&conf->r10bio_pool); raid10_free_conf(conf);
safe_put_page(conf->tmppage);
kfree(conf->mirrors);
kfree(conf);
mddev->private = NULL; mddev->private = NULL;
out: out:
return -EIO; return -EIO;
...@@ -3929,15 +3934,7 @@ static int raid10_run(struct mddev *mddev) ...@@ -3929,15 +3934,7 @@ static int raid10_run(struct mddev *mddev)
static void raid10_free(struct mddev *mddev, void *priv) static void raid10_free(struct mddev *mddev, void *priv)
{ {
struct r10conf *conf = priv; raid10_free_conf(priv);
mempool_exit(&conf->r10bio_pool);
safe_put_page(conf->tmppage);
kfree(conf->mirrors);
kfree(conf->mirrors_old);
kfree(conf->mirrors_new);
bioset_exit(&conf->bio_split);
kfree(conf);
} }
static void raid10_quiesce(struct mddev *mddev, int quiesce) static void raid10_quiesce(struct mddev *mddev, int quiesce)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册