Skip to contentSkip to conversation

soc: amlogic: meson-gx-socinfo: Add of_node_put() before return

PATCH In review Nishka Dasgupta 3 participants 3 messages Aug 19, 2019 – Aug 20, 2019 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: amlogic: meson-gx-socinfo: Add of_node_put() before return

The variable np in function meson_gx_socinfo_init takes the return value of of_find_compatible_node, which gets a node but does not put it. If this node is not put it may cause a memory leak. Hence put np after its usefulness has been exhausted.
Issue found with Coccinelle.

---
 drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/amlogic/meson-gx-socinfo.c +3 -1
index bca34954518e..13695a72c695 100644
@@ -138,8 +138,10 @@ static int __init meson_gx_socinfo_init(void)
 	}
 
 	/* check if chip-id is available */
-	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
+	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
+		of_node_put(np);
 		return -ENODEV;
+	}
 
 	/* node should be a syscon */
 	regmap = syscon_node_to_regmap(np);
Signature · 7 lines
2.19.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Nishka Dasgupta

The variable np in function meson_gx_socinfo_init takes the return value of of_find_compatible_node, which gets a node but does not put it. If this node is not put it may cause a memory leak. Hence put np after its usefulness has been exhausted.
Issue found with Coccinelle.

---
 drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/amlogic/meson-gx-socinfo.c +0 -0
index bca34954518e..13695a72c695 100644
@@ -138,8 +138,10 @@ static int __init meson_gx_socinfo_init(void)
 	}

drivers/soc/amlogic/meson-gx-socinfo.c static int __init meson_gx_socinfo_init(void) · line 147

Quoted 10 lines
drivers/soc/amlogic/meson-gx-socinfo.c +3 -1
 
 	/* check if chip-id is available */
-	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
+	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
+		of_node_put(np);
 		return -ENODEV;
+	}
 
 	/* node should be a syscon */
 	regmap = syscon_node_to_regmap(np);

Thanks !

Would need :

Fixes a9daaba2965e ("soc: Add Amlogic SoC Information driver")

Neil

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

maintainer
#2 lore raw
Quoted 32 lines · Neil Armstrong
Quoted 18 lines · Nishka Dasgupta

The variable np in function meson_gx_socinfo_init takes the return value of of_find_compatible_node, which gets a node but does not put it. If this node is not put it may cause a memory leak. Hence put np after its usefulness has been exhausted.
Issue found with Coccinelle.

---
 drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/amlogic/meson-gx-socinfo.c +0 -0
index bca34954518e..13695a72c695 100644
@@ -138,8 +138,10 @@ static int __init meson_gx_socinfo_init(void)
 	}

drivers/soc/amlogic/meson-gx-socinfo.c static int __init meson_gx_socinfo_init(void) · line 147

Quoted 10 lines
drivers/soc/amlogic/meson-gx-socinfo.c +3 -1
 
 	/* check if chip-id is available */
-	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
+	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
+		of_node_put(np);
 		return -ENODEV;
+	}
 
 	/* node should be a syscon */
 	regmap = syscon_node_to_regmap(np);

Thanks !

Quoted 4 lines

Would need :

Fixes a9daaba2965e ("soc: Add Amlogic SoC Information driver")

Thanks.

Queued for v5.4 with Neil's tag and the Fixes tag.

Kevin

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