Skip to contentSkip to conversation

ARM: vexpress: fix iounmap missing after of_iomap in SMP prepare

PATCH Applied Sudeep Holla 2 participants 3 messages Nov 4 – Nov 16

Subsystems (4)
lore
Share & tools
lore

Sudeep Holla

author maintainer
#0 lore raw

PATCH 1/1 ARM: vexpress: fix iounmap missing after of_iomap in SMP prepare

of_iomap() maps a region of device memory and returns a pointer that must later be released with iounmap(). Currently return value from of_iomap() is passed directly to scu_enable() without saving it, making it impossible to unmap afterwards, causing an I/O memory leak.

Store the mapped base address in a local variable, check it for NULL, call scu_enable(), then release the mapping with iounmap().

---
 arch/arm/mach-versatile/platsmp-vexpress.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/arm/mach-versatile/platsmp-vexpress.c +8 -2
index b810ad50b98c..e3c8ee4c52fb 100644
@@ -63,9 +63,15 @@ static void __init vexpress_smp_dt_prepare_cpus(unsigned int max_cpus)
 {
 	struct device_node *scu __free(device_node) =
 		of_find_matching_node(NULL, vexpress_smp_dt_scu_match);
+	void __iomem *scu_base;
 
-	if (scu)
-		scu_enable(of_iomap(scu, 0));
+	if (scu) {
+		scu_base = of_iomap(scu, 0);
+		if (scu_base) {
+			scu_enable(scu_base);
+			iounmap(scu_base);
+		}
+	}
 
 	/*
 	 * Write the address of secondary startup into the
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Sudeep Holla

of_iomap() maps a region of device memory and returns a pointer that must later be released with iounmap(). Currently return value from of_iomap() is passed directly to scu_enable() without saving it, making it impossible to unmap afterwards, causing an I/O memory leak.

Quoted 7 lines

Store the mapped base address in a local variable, check it for NULL, call scu_enable(), then release the mapping with iounmap().

Yours,
Linus Walleij

author maintainer Applied
#2 lore raw
In reply to Sudeep Holla
Quoted 9 lines · Sudeep Holla

of_iomap() maps a region of device memory and returns a pointer that must later be released with iounmap(). Currently return value from of_iomap() is passed directly to scu_enable() without saving it, making it impossible to unmap afterwards, causing an I/O memory leak.

Store the mapped base address in a local variable, check it for NULL, call scu_enable(), then release the mapping with iounmap().

[...]

Applied to sudeep.holla/linux (for-next/vexpress/updates), thanks!

[1/1] ARM: vexpress: fix iounmap missing after of_iomap in SMP prepare

      https://git.kernel.org/sudeep.holla/c/3ce981979606
Signature · 2 lines
Regards,
Sudeep