All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
@ 2020-06-30  7:52 Gavin Shan
  2020-07-08 22:02 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Gavin Shan @ 2020-06-30  7:52 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: mark.rutland, catalin.marinas, will, sudeep.holla

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>
---
v3: Pick r-b from Sudeep and rebases to 5.8.rc3
---
 drivers/firmware/psci/psci_checker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
index 873841af8d57..d9b1a2d71223 100644
--- a/drivers/firmware/psci/psci_checker.c
+++ b/drivers/firmware/psci/psci_checker.c
@@ -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;
 		}
-- 
2.23.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
  2020-06-30  7:52 [PATCH v3] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups() Gavin Shan
@ 2020-07-08 22:02 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2020-07-08 22:02 UTC (permalink / raw)
  To: linux-arm-kernel, Gavin Shan
  Cc: mark.rutland, catalin.marinas, kernel-team, Will Deacon, sudeep.holla

On Tue, 30 Jun 2020 17:52:27 +1000, Gavin Shan wrote:
> 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.

Applied to arm64 (for-next/fixes), thanks!

[1/1] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
      https://git.kernel.org/arm64/c/c377e67c6271

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-08 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30  7:52 [PATCH v3] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups() Gavin Shan
2020-07-08 22:02 ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.