From: Xie XiuQi <xiexiuqi(a)huawei.com>
commit 310dfdff5181caec78c6527845924b66b3bdcff9 openEuler-1.0
hulk inclusion
category: bugfix
bugzilla: 14212
CVE: NA
When failed to init domain list, we should destroy
it to avoid memory leak.
Signed-off-by: Xie XiuQi <xiexiuqi(a)huawei.com>
Reviewed-by: Hanjun Guo <guohanjun(a)huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
Signed-off-by: Xin Hao <haoxing990(a)gmail.com>
---
arch/arm64/kernel/mpam.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c
index bd94cd31c2fa..d0b4f6ab70ad 100644
--- a/arch/arm64/kernel/mpam.c
+++ b/arch/arm64/kernel/mpam.c
@@ -1140,6 +1140,21 @@ struct rdt_domain *mpam_find_domain(struct resctrl_resource *r, int
id,
return NULL;
}
+static void mpam_domains_destroy(struct resctrl_resource *r)
+{
+ struct list_head *pos, *q;
+ struct rdt_domain *d;
+
+ list_for_each_safe(pos, q, &r->domains) {
+ d = list_entry(pos, struct rdt_domain, list);
+ list_del(pos);
+ if (d) {
+ kfree(d->ctrl_val);
+ kfree(d);
+ }
+ }
+}
+
static void mpam_domains_init(struct resctrl_resource *r)
{
int i, cpu, id = 0;
@@ -1167,6 +1182,7 @@ static void mpam_domains_init(struct resctrl_resource *r)
d = mpam_find_domain(r, id, &add_pos);
if (IS_ERR(d)) {
+ mpam_domains_destroy(r);
pr_warn("Could't find cache id for cpu %d\n", cpu);
return;
}
@@ -1174,8 +1190,10 @@ static void mpam_domains_init(struct resctrl_resource *r)
if (!d)
d = kzalloc(sizeof(*d), GFP_KERNEL);
- if (!d)
+ if (!d) {
+ mpam_domains_destroy(r);
return;
+ }
d->id = id;
d->base = n->base;
@@ -1221,6 +1239,8 @@ static void mpam_domains_init(struct resctrl_resource *r)
d->ctrl_val = kmalloc_array(rr->num_partid, sizeof(*d->ctrl_val),
GFP_KERNEL);
if (!d->ctrl_val) {
kfree(d);
+ mpam_domains_destroy(r);
+
return;
}
--
2.31.0