Skip to contentSkip to conversation

drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()

PATCH Superseded Gavin Shan 2 participants 2 messages Jan 30, 2020 – Jan 31, 2020 Power state coordination interface (psci)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Gavin Shan

author
#0 lore raw

PATCH v2 1/1 drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()

The CPU mask (@tmp) should be free'd 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 with CONFIG_CPUMASK_OFFSTACK.

---
v2: Free @tmp on failing to allocate @cpu_groups

---
 drivers/firmware/psci/psci_checker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/firmware/psci/psci_checker.c +4 -1
index 6a445397771c..03eb798ad3ed 100644
@@ -157,8 +157,10 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
 
 	cpu_groups = kcalloc(nb_available_cpus, sizeof(cpu_groups),
 			     GFP_KERNEL);
-	if (!cpu_groups)
+	if (!cpu_groups) {
+		free_cpumask_var(tmp);
 		return -ENOMEM;
+	}
 
 	cpumask_copy(tmp, cpu_online_mask);
 
@@ -167,6 +169,7 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
 			topology_core_cpumask(cpumask_any(tmp));
 
 		if (!alloc_cpumask_var(&cpu_groups[num_groups], GFP_KERNEL)) {
+			free_cpumask_var(tmp);
 			free_cpu_groups(num_groups, &cpu_groups);
 			return -ENOMEM;
 		}
Signature · 7 lines
2.23.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Gavin Shan

The CPU mask (@tmp) should be free'd 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 with CONFIG_CPUMASK_OFFSTACK.

--
Regards,
Sudeep

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel