linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] clk: imx: imx8m: avoid memory leak
@ 2020-07-28  2:54 peng.fan
  2020-07-28  2:54 ` [PATCH 2/2] clk: imx: imx8m: use devm_of_clk_add_hw_provider peng.fan
  2020-07-28  8:30 ` [PATCH 1/2] clk: imx: imx8m: avoid memory leak Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: peng.fan @ 2020-07-28  2:54 UTC (permalink / raw)
  To: sboyd, shawnguo, s.hauer, festevam, abel.vesa
  Cc: kernel, linux-imx, Anson.Huang, linux-clk, linux-arm-kernel,
	linux-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

Use devm_kzalloc to avoid memory leak when probe fail.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/imx/clk-imx8mm.c |  3 +--
 drivers/clk/imx/clk-imx8mn.c | 15 +++++----------
 drivers/clk/imx/clk-imx8mp.c |  2 +-
 drivers/clk/imx/clk-imx8mq.c |  3 +--
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/imx/clk-imx8mm.c b/drivers/clk/imx/clk-imx8mm.c
index b793264c21c6..b43dbe305e7a 100644
--- a/drivers/clk/imx/clk-imx8mm.c
+++ b/drivers/clk/imx/clk-imx8mm.c
@@ -306,8 +306,7 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
 	void __iomem *base;
 	int ret, i;
 
-	clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
-					  IMX8MM_CLK_END), GFP_KERNEL);
+	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MM_CLK_END), GFP_KERNEL);
 	if (WARN_ON(!clk_hw_data))
 		return -ENOMEM;
 
diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c
index 213cc37b3173..4189f7f6980e 100644
--- a/drivers/clk/imx/clk-imx8mn.c
+++ b/drivers/clk/imx/clk-imx8mn.c
@@ -299,8 +299,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 	void __iomem *base;
 	int ret, i;
 
-	clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
-					  IMX8MN_CLK_END), GFP_KERNEL);
+	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MN_CLK_END), GFP_KERNEL);
 	if (WARN_ON(!clk_hw_data))
 		return -ENOMEM;
 
@@ -318,10 +317,8 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 	np = of_find_compatible_node(NULL, NULL, "fsl,imx8mn-anatop");
 	base = of_iomap(np, 0);
 	of_node_put(np);
-	if (WARN_ON(!base)) {
-		ret = -ENOMEM;
-		goto unregister_hws;
-	}
+	if (WARN_ON(!base))
+		return -ENOMEM;
 
 	hws[IMX8MN_AUDIO_PLL1_REF_SEL] = imx_clk_hw_mux("audio_pll1_ref_sel", base + 0x0, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
 	hws[IMX8MN_AUDIO_PLL2_REF_SEL] = imx_clk_hw_mux("audio_pll2_ref_sel", base + 0x14, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
@@ -407,10 +404,8 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 
 	np = dev->of_node;
 	base = devm_platform_ioremap_resource(pdev, 0);
-	if (WARN_ON(IS_ERR(base))) {
-		ret = PTR_ERR(base);
-		goto unregister_hws;
-	}
+	if (WARN_ON(IS_ERR(base)))
+		return PTR_ERR(base);
 
 	/* CORE */
 	hws[IMX8MN_CLK_A53_DIV] = imx8m_clk_hw_composite_core("arm_a53_div", imx8mn_a53_sels, base + 0x8000);
diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c
index ca747712400f..f6ec7b2b8038 100644
--- a/drivers/clk/imx/clk-imx8mp.c
+++ b/drivers/clk/imx/clk-imx8mp.c
@@ -447,7 +447,7 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
 		return PTR_ERR(ccm_base);
 	}
 
-	clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL);
+	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL);
 	if (WARN_ON(!clk_hw_data)) {
 		iounmap(anatop_base);
 		return -ENOMEM;
diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c
index a64aace213c2..0106a33c24a4 100644
--- a/drivers/clk/imx/clk-imx8mq.c
+++ b/drivers/clk/imx/clk-imx8mq.c
@@ -288,8 +288,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
 	void __iomem *base;
 	int err, i;
 
-	clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
-					  IMX8MQ_CLK_END), GFP_KERNEL);
+	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MQ_CLK_END), GFP_KERNEL);
 	if (WARN_ON(!clk_hw_data))
 		return -ENOMEM;
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] clk: imx: imx8m: use devm_of_clk_add_hw_provider
  2020-07-28  2:54 [PATCH 1/2] clk: imx: imx8m: avoid memory leak peng.fan
@ 2020-07-28  2:54 ` peng.fan
  2020-07-28  8:30 ` [PATCH 1/2] clk: imx: imx8m: avoid memory leak Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: peng.fan @ 2020-07-28  2:54 UTC (permalink / raw)
  To: sboyd, shawnguo, s.hauer, festevam, abel.vesa
  Cc: kernel, linux-imx, Anson.Huang, linux-clk, linux-arm-kernel,
	linux-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

Use devm_of_clk_add_hw_provider to simplify code.
To i.MX8MP, also add err handling.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/imx/clk-imx8mm.c | 9 ++-------
 drivers/clk/imx/clk-imx8mn.c | 9 ++-------
 drivers/clk/imx/clk-imx8mp.c | 8 ++++++--
 drivers/clk/imx/clk-imx8mq.c | 9 ++-------
 4 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/drivers/clk/imx/clk-imx8mm.c b/drivers/clk/imx/clk-imx8mm.c
index b43dbe305e7a..fc2c1a0c9ff2 100644
--- a/drivers/clk/imx/clk-imx8mm.c
+++ b/drivers/clk/imx/clk-imx8mm.c
@@ -615,10 +615,10 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
 
 	imx_check_clk_hws(hws, IMX8MM_CLK_END);
 
-	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
 	if (ret < 0) {
 		dev_err(dev, "failed to register clks for i.MX8MM\n");
-		goto unregister_hws;
+		return ret;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(uart_clk_ids); i++) {
@@ -630,11 +630,6 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
 	imx_register_uart_clocks(uart_hws);
 
 	return 0;
-
-unregister_hws:
-	imx_unregister_hw_clocks(hws, IMX8MM_CLK_END);
-
-	return ret;
 }
 
 static const struct of_device_id imx8mm_clk_of_match[] = {
diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c
index 4189f7f6980e..3620a419eb83 100644
--- a/drivers/clk/imx/clk-imx8mn.c
+++ b/drivers/clk/imx/clk-imx8mn.c
@@ -562,10 +562,10 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 
 	imx_check_clk_hws(hws, IMX8MN_CLK_END);
 
-	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
 	if (ret < 0) {
 		dev_err(dev, "failed to register hws for i.MX8MN\n");
-		goto unregister_hws;
+		return ret;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(uart_clk_ids); i++) {
@@ -577,11 +577,6 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 	imx_register_uart_clocks(uart_hws);
 
 	return 0;
-
-unregister_hws:
-	imx_unregister_hw_clocks(hws, IMX8MN_CLK_END);
-
-	return ret;
 }
 
 static const struct of_device_id imx8mn_clk_of_match[] = {
diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c
index f6ec7b2b8038..43117f387460 100644
--- a/drivers/clk/imx/clk-imx8mp.c
+++ b/drivers/clk/imx/clk-imx8mp.c
@@ -432,7 +432,7 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
 	void __iomem *anatop_base, *ccm_base;
-	int i;
+	int ret, i;
 
 	np = of_find_compatible_node(NULL, NULL, "fsl,imx8mp-anatop");
 	anatop_base = of_iomap(np, 0);
@@ -741,7 +741,11 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
 
 	imx_check_clk_hws(hws, IMX8MP_CLK_END);
 
-	of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
+	if (ret < 0) {
+		dev_err(dev, "failed to register hws for i.MX8MN\n");
+		return ret;
+	}
 
 	for (i = 0; i < ARRAY_SIZE(uart_clk_ids); i++) {
 		int index = uart_clk_ids[i];
diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c
index 0106a33c24a4..7c0a84cc9501 100644
--- a/drivers/clk/imx/clk-imx8mq.c
+++ b/drivers/clk/imx/clk-imx8mq.c
@@ -600,10 +600,10 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
 
 	imx_check_clk_hws(hws, IMX8MQ_CLK_END);
 
-	err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+	err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
 	if (err < 0) {
 		dev_err(dev, "failed to register hws for i.MX8MQ\n");
-		goto unregister_hws;
+		return err;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(uart_clk_ids); i++) {
@@ -615,11 +615,6 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
 	imx_register_uart_clocks(uart_hws);
 
 	return 0;
-
-unregister_hws:
-	imx_unregister_hw_clocks(hws, IMX8MQ_CLK_END);
-
-	return err;
 }
 
 static const struct of_device_id imx8mq_clk_of_match[] = {
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] clk: imx: imx8m: avoid memory leak
  2020-07-28  2:54 [PATCH 1/2] clk: imx: imx8m: avoid memory leak peng.fan
  2020-07-28  2:54 ` [PATCH 2/2] clk: imx: imx8m: use devm_of_clk_add_hw_provider peng.fan
@ 2020-07-28  8:30 ` Stephen Boyd
  2020-07-28  9:38   ` Peng Fan
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2020-07-28  8:30 UTC (permalink / raw)
  To: abel.vesa, festevam, peng.fan, s.hauer, shawnguo
  Cc: kernel, linux-imx, Anson.Huang, linux-clk, linux-arm-kernel,
	linux-kernel, Peng Fan

Quoting peng.fan@nxp.com (2020-07-27 19:54:48)
> From: Peng Fan <peng.fan@nxp.com>
> 
> Use devm_kzalloc to avoid memory leak when probe fail.

Please add () to functions in commit text.

> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH 1/2] clk: imx: imx8m: avoid memory leak
  2020-07-28  8:30 ` [PATCH 1/2] clk: imx: imx8m: avoid memory leak Stephen Boyd
@ 2020-07-28  9:38   ` Peng Fan
  0 siblings, 0 replies; 4+ messages in thread
From: Peng Fan @ 2020-07-28  9:38 UTC (permalink / raw)
  To: Stephen Boyd, Abel Vesa, festevam, s.hauer, shawnguo
  Cc: kernel, dl-linux-imx, Anson Huang, linux-clk, linux-arm-kernel,
	linux-kernel

> Subject: Re: [PATCH 1/2] clk: imx: imx8m: avoid memory leak
> 
> Quoting peng.fan@nxp.com (2020-07-27 19:54:48)
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > Use devm_kzalloc to avoid memory leak when probe fail.
> 
> Please add () to functions in commit text.

V2 is just out, please help review there.

Thanks,
Peng.

> 
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-28  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28  2:54 [PATCH 1/2] clk: imx: imx8m: avoid memory leak peng.fan
2020-07-28  2:54 ` [PATCH 2/2] clk: imx: imx8m: use devm_of_clk_add_hw_provider peng.fan
2020-07-28  8:30 ` [PATCH 1/2] clk: imx: imx8m: avoid memory leak Stephen Boyd
2020-07-28  9:38   ` Peng Fan

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).