diff mbox series

[v2] thermal: imx_sc_thermal: Fix refcount leak in imx_sc_thermal_probe

Message ID 20220517055121.18092-1-linmq006@gmail.com
State Accepted
Commit 09700c504d8e63faffd2a2235074e8c5d130cb8f
Headers show
Series [v2] thermal: imx_sc_thermal: Fix refcount leak in imx_sc_thermal_probe | expand

Commit Message

Miaoqian Lin May 17, 2022, 5:51 a.m. UTC
of_find_node_by_name() 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: e20db70dba1c ("thermal: imx_sc: add i.MX system controller thermal support")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- use goto statement, also move of_node_put(sensor_np) to goto label
v1 Link: https://lore.kernel.org/all/20220516073151.25918-1-linmq006@gmail.com/
---
 drivers/thermal/imx_sc_thermal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c
index 8d76dbfde6a9..331a241eb0ef 100644
--- a/drivers/thermal/imx_sc_thermal.c
+++ b/drivers/thermal/imx_sc_thermal.c
@@ -94,8 +94,8 @@  static int imx_sc_thermal_probe(struct platform_device *pdev)
 		sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL);
 		if (!sensor) {
 			of_node_put(child);
-			of_node_put(sensor_np);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto put_node;
 		}
 
 		ret = thermal_zone_of_get_sensor_id(child,
@@ -124,7 +124,9 @@  static int imx_sc_thermal_probe(struct platform_device *pdev)
 			dev_warn(&pdev->dev, "failed to add hwmon sysfs attributes\n");
 	}
 
+put_node:
 	of_node_put(sensor_np);
+	of_node_put(np);
 
 	return ret;
 }