Skip to contentSkip to conversation

MIPS: CPC: Fix refcount leak in mips_cpc_default_phys_base

PATCH In review Miaoqian Lin 3 participants 3 messages May 16, 2022 – May 23, 2022 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: CPC: Fix refcount leak in mips_cpc_default_phys_base

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 791412dafbbf ("MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base()")
---
 arch/mips/kernel/mips-cpc.c | 1 +
 1 file changed, 1 insertion(+)
arch/mips/kernel/mips-cpc.c +1 -0
index 17aff13cd7ce..3e386f7e1545 100644
@@ -28,6 +28,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)
 	cpc_node = of_find_compatible_node(of_root, NULL, "mti,mips-cpc");
 	if (cpc_node) {
 		err = of_address_to_resource(cpc_node, 0, &res);
+		of_node_put(cpc_node);
 		if (!err)
 			return res.start;
 	}
Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · Miaoqian Lin

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 791412dafbbf ("MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base()")
---
 arch/mips/kernel/mips-cpc.c | 1 +
 1 file changed, 1 insertion(+)
arch/mips/kernel/mips-cpc.c +1 -0
index 17aff13cd7ce..3e386f7e1545 100644
@@ -28,6 +28,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)
 	cpc_node = of_find_compatible_node(of_root, NULL, "mti,mips-cpc");
 	if (cpc_node) {
 		err = of_address_to_resource(cpc_node, 0, &res);
+		of_node_put(cpc_node);
 		if (!err)
 			return res.start;
 	}
Signature · 1 line
2.25.1

this is already fixed in mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
Reviewed-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 6 lines · Miaoqian Lin

of_find_compatible_node() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 791412dafbbf ("MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base()")

Right. It's similar to the CDMM fix:
commit 4528668ca331 ("mips: cdmm: Fix refcount leak in mips_cdmm_phys_base")

-Sergey

Quoted 19 lines
---
 arch/mips/kernel/mips-cpc.c | 1 +
 1 file changed, 1 insertion(+)
arch/mips/kernel/mips-cpc.c +1 -0
index 17aff13cd7ce..3e386f7e1545 100644
@@ -28,6 +28,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)
 	cpc_node = of_find_compatible_node(of_root, NULL, "mti,mips-cpc");
 	if (cpc_node) {
 		err = of_address_to_resource(cpc_node, 0, &res);
+		of_node_put(cpc_node);
 		if (!err)
 			return res.start;
 	}
Signature · 1 line
2.25.1