Skip to content

Commit c377e67

Browse files
Gavin Shanwilldeacon
Gavin Shan
authored andcommitted
drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
The CPU mask (@tmp) should be released on failing to allocate @cpu_groups or any of its elements. Otherwise, it leads to memory leakage because the CPU mask variable is dynamically allocated when CONFIG_CPUMASK_OFFSTACK is enabled. Signed-off-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://lore.kernel.org/r/20200630075227.199624-1-gshan@redhat.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 68cf617 commit c377e67

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/firmware/psci/psci_checker.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
157157

158158
cpu_groups = kcalloc(nb_available_cpus, sizeof(cpu_groups),
159159
GFP_KERNEL);
160-
if (!cpu_groups)
160+
if (!cpu_groups) {
161+
free_cpumask_var(tmp);
161162
return -ENOMEM;
163+
}
162164

163165
cpumask_copy(tmp, cpu_online_mask);
164166

@@ -167,6 +169,7 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
167169
topology_core_cpumask(cpumask_any(tmp));
168170

169171
if (!alloc_cpumask_var(&cpu_groups[num_groups], GFP_KERNEL)) {
172+
free_cpumask_var(tmp);
170173
free_cpu_groups(num_groups, &cpu_groups);
171174
return -ENOMEM;
172175
}

0 commit comments

Comments
 (0)