Skip to content

Commit ab6a211

Browse files
shakeelbsuryasaimadhu
authored andcommitted
x86/resctrl: Fix potential memory leak
set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. At the moment, this function is called with only valid levels but move the allocation after the valid level checks in order to make it more robust and future proof. [ bp: Massage commit message. ] Fixes: 99adde9 ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG") Signed-off-by: Shakeel Butt <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Reinette Chatre <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent e278af8 commit ab6a211

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,16 +1741,16 @@ static int set_cache_qos_cfg(int level, bool enable)
17411741
struct rdt_domain *d;
17421742
int cpu;
17431743

1744-
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
1745-
return -ENOMEM;
1746-
17471744
if (level == RDT_RESOURCE_L3)
17481745
update = l3_qos_cfg_update;
17491746
else if (level == RDT_RESOURCE_L2)
17501747
update = l2_qos_cfg_update;
17511748
else
17521749
return -EINVAL;
17531750

1751+
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
1752+
return -ENOMEM;
1753+
17541754
r_l = &rdt_resources_all[level];
17551755
list_for_each_entry(d, &r_l->domains, list) {
17561756
/* Pick one CPU from each domain instance to update MSR */

0 commit comments

Comments
 (0)