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

Liang He windhl at 126.com
Sat Jun 18 18:39:41 PDT 2022


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.

Signed-off-by: Liang He <windhl at 126.com>
---
 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(-)

diff --git a/arch/arm/mm/cache-feroceon-l2.c b/arch/arm/mm/cache-feroceon-l2.c
index 5c1b7a7b9af6..d5b7878094fd 100644
--- a/arch/arm/mm/cache-feroceon-l2.c
+++ b/arch/arm/mm/cache-feroceon-l2.c
@@ -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;
diff --git a/arch/arm/mm/cache-tauros2.c b/arch/arm/mm/cache-tauros2.c
index 88255bea65e4..05eab6e44cfc 100644
--- a/arch/arm/mm/cache-tauros2.c
+++ b/arch/arm/mm/cache-tauros2.c
@@ -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");
-- 
2.25.1




More information about the linux-arm-kernel mailing list