linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miaoqian Lin <linmq006@gmail.com>
To: Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Miaoqian Lin <linmq006@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] soc: imx: gpc: Fix refcount leak in imx_gpc_probe
Date: Thu,  2 Jun 2022 17:23:52 +0400	[thread overview]
Message-ID: <20220602132355.29847-1-linmq006@gmail.com> (raw)

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: format:721cabf6c660 ("soc: imx: move PGC handling to a new GPC driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 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

                 reply	other threads:[~2022-06-02 13:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220602132355.29847-1-linmq006@gmail.com \
    --to=linmq006@gmail.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).