[PATCH v2] soc: imx: gpc: Fix refcount leak in imx_gpc_probe
From: Miaoqian Lin <hidden>
Date: 2022-06-03 13:03:01
Also in:
lkml
Subsystem:
the rest · Maintainer:
Linus Torvalds
of_get_child_by_name() returns a node pointer with refcount
incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.
Fixes: 721cabf6c660 ("soc: imx: move PGC handling to a new GPC driver")
Signed-off-by: Miaoqian Lin <redacted>
---
changes in v2:
- update Fixes tag.
v1 Link: https://lore.kernel.org/r/20220602132355.29847-1-linmq006@gmail.com (local)
---
drivers/soc/imx/gpc.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c
index 90a8b2c0676f..5df47e6d7585 100644
--- a/drivers/soc/imx/gpc.c
+++ b/drivers/soc/imx/gpc.c@@ -419,8 +419,10 @@ static int imx_gpc_probe(struct platform_device *pdev) return 0; base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(base)) - return PTR_ERR(base); + if (IS_ERR(base)) { + ret = PTR_ERR(base); + goto put_pgc_node; + } regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, &imx_gpc_regmap_config);
@@ -428,7 +430,7 @@ static int imx_gpc_probe(struct platform_device *pdev) ret = PTR_ERR(regmap); dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); - return ret; + goto put_pgc_node; } /*
@@ -464,15 +466,18 @@ static int imx_gpc_probe(struct platform_device *pdev) int domain_index; ipg_clk = devm_clk_get(&pdev->dev, "ipg"); - if (IS_ERR(ipg_clk)) - return PTR_ERR(ipg_clk); + if (IS_ERR(ipg_clk)) { + ret = PTR_ERR(ipg_clk); + goto put_pgc_node; + } + ipg_rate_mhz = clk_get_rate(ipg_clk) / 1000000; for_each_child_of_node(pgc_node, np) { ret = of_property_read_u32(np, "reg", &domain_index); if (ret) { of_node_put(np); - return ret; + goto put_pgc_node; } if (domain_index >= of_id_data->num_domains) continue;
@@ -481,7 +486,8 @@ static int imx_gpc_probe(struct platform_device *pdev) domain_index); if (!pd_pdev) { of_node_put(np); - return -ENOMEM; + ret = -ENOMEM; + goto put_pgc_node; } ret = platform_device_add_data(pd_pdev,
@@ -490,7 +496,7 @@ static int imx_gpc_probe(struct platform_device *pdev) if (ret) { platform_device_put(pd_pdev); of_node_put(np); - return ret; + goto put_pgc_node; } domain = pd_pdev->dev.platform_data; domain->regmap = regmap;
@@ -503,12 +509,17 @@ static int imx_gpc_probe(struct platform_device *pdev) if (ret) { platform_device_put(pd_pdev); of_node_put(np); - return ret; + goto put_pgc_node; } } } + of_node_put(pgc_node); return 0; + +put_pgc_node: + of_node_put(pgc_node); + return ret; } static int imx_gpc_remove(struct platform_device *pdev)
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel