Skip to contentSkip to conversation

arm/mm: Fix refcount leak bugs in cache

PATCH In review Liang He 2 participants 2 messages Jun 19, 2022 – Jun 22, 2022 Arm (32-bit)

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v3 1/1 arm/mm: Fix refcount leak bugs in cache

In feroceon_of_init() and tauros2_init(), of_find_matching_node() will return a node pointer with refcount incremented. We should use of_node_put() in fail path or when it is not used anymore.

---
changelog:

v3: (1) merge arm/mm leak bugs (2) fix bugs intro-ed by v2
v2: (1) use real name (2) normalize coding style
v1: (1) fix leak bug

 arch/arm/mm/cache-feroceon-l2.c | 6 +++++-
 arch/arm/mm/cache-tauros2.c     | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/arm/mm/cache-feroceon-l2.c +5 -1
index 5c1b7a7b9af6..d5b7878094fd 100644
@@ -376,8 +376,10 @@ int __init feroceon_of_init(void)
 	node = of_find_matching_node(NULL, feroceon_ids);
 	if (node && of_device_is_compatible(node, "marvell,kirkwood-cache")) {
 		base = of_iomap(node, 0);
-		if (!base)
+		if (!base) {
+			of_node_put(node);
 			return -ENOMEM;
+		}
 
 		if (l2_wt_override)
 			writel(readl(base) | L2_WRITETHROUGH_KIRKWOOD, base);
@@ -385,6 +387,8 @@ int __init feroceon_of_init(void)
 			writel(readl(base) & ~L2_WRITETHROUGH_KIRKWOOD, base);
 	}
 
+	of_node_put(node);
+
 	feroceon_l2_init(l2_wt_override);
 
 	return 0;
arch/arm/mm/cache-tauros2.c +1 -0
index 88255bea65e4..05eab6e44cfc 100644
@@ -294,6 +294,7 @@ void __init tauros2_init(unsigned int features)
 		pr_info("Not found marvell,tauros2-cache, disable it\n");
 	} else {
 		ret = of_property_read_u32(node, "marvell,tauros2-cache-features", &f);
+		of_node_put(node);
 		if (ret) {
 			pr_info("Not found marvell,tauros-cache-features property, "
 				"disable extra features\n");
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Liang He

In feroceon_of_init() and tauros2_init(), of_find_matching_node() will return a node pointer with refcount incremented. We should use of_node_put() in fail path or when it is not used anymore.

Quoted 8 lines

---
changelog:

v3: (1) merge arm/mm leak bugs (2) fix bugs intro-ed by v2
v2: (1) use real name (2) normalize coding style
v1: (1) fix leak bug

Before applying the patch please check it carefully. Previous evidence [1][2] suggests that not it was not even compiled.

[1] https://lore.kernel.org/all/[email protected]/

[2]
https://lore.kernel.org/all/[email protected]/

Best regards,
Krzysztof

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