[PATCH v2] x86/resctrl: Fix potential memory leak
From: Shakeel Butt
Date: Fri Dec 20 2019 - 11:44:19 EST
The set_cache_qos_cfg() is leaking memory when the given level is not
RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function
is called with only valid levels but to make it more robust and future
proof, we should be handling the error path gracefully.
Fixes: 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")
Signed-off-by: Shakeel Butt <shakeelb@xxxxxxxxxx>
Acked-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
---
Changes since v1:
- Updated the commit message
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 2e3b06d6bbc6..a0c279c7f4b9 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable)
update = l3_qos_cfg_update;
else if (level == RDT_RESOURCE_L2)
update = l2_qos_cfg_update;
- else
+ else {
+ free_cpumask_var(cpu_mask);
return -EINVAL;
+ }
r_l = &rdt_resources_all[level];
list_for_each_entry(d, &r_l->domains, list) {
--
2.24.1.735.g03f4e72817-goog