Skip to contentSkip to conversation

clk: mediatek: mt6735-apmixedsys: Fix an error handling path in clk_mt6735_apmixed_probe()

PATCH Applied Christophe JAILLET 3 participants 3 messages Oct 25, 2024 – Nov 14, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: mediatek: mt6735-apmixedsys: Fix an error handling path in clk_mt6735_apmixed_probe()

If an error occurs after a successful mtk_alloc_clk_data(), mtk_free_clk_data() should be called, as already done in the .remove() function.

Switch to mtk_devm_alloc_clk_data() in order to fix the memory leak in the probe function, and simplify the remove function.

Fixes 43c04ed79189 ("clk: mediatek: Add drivers for MediaTek MT6735 main clock and reset drivers")

---
Compile tested only

---
 drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/mediatek/clk-mt6735-apmixedsys.c +1 -2
index 104722a61dfd..e0949911e8f7 100644
@@ -88,7 +88,7 @@ static int clk_mt6735_apmixed_probe(struct platform_device *pdev)
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
-	clk_data = mtk_alloc_clk_data(ARRAY_SIZE(apmixedsys_plls));
+	clk_data = mtk_devm_alloc_clk_data(&pdev->dev, ARRAY_SIZE(apmixedsys_plls));
 	if (!clk_data)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, clk_data);
@@ -114,7 +114,6 @@ static void clk_mt6735_apmixed_remove(struct platform_device *pdev)
 	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
 
 	mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls), clk_data);
-	mtk_free_clk_data(clk_data);
 }
 
 static const struct of_device_id of_match_mt6735_apmixedsys[] = {
Signature · 1 line
2.47.0
maintainer Tested-by on v1 1/1
#1 lore raw
Quoted 37 lines · Christophe JAILLET

If an error occurs after a successful mtk_alloc_clk_data(), mtk_free_clk_data() should be called, as already done in the .remove() function.

Switch to mtk_devm_alloc_clk_data() in order to fix the memory leak in the probe function, and simplify the remove function.

Fixes 43c04ed79189 ("clk: mediatek: Add drivers for MediaTek MT6735 main clock and reset drivers")

---
Compile tested only

---
  drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/mediatek/clk-mt6735-apmixedsys.c +1 -3
index 104722a61dfd..e0949911e8f7 100644
@@ -88,7 +88,7 @@ static int clk_mt6735_apmixed_probe(struct platform_device *pdev)
  	if (IS_ERR(base))
  		return PTR_ERR(base);
 
-	clk_data = mtk_alloc_clk_data(ARRAY_SIZE(apmixedsys_plls));
+	clk_data = mtk_devm_alloc_clk_data(&pdev->dev, ARRAY_SIZE(apmixedsys_plls));
  	if (!clk_data)
  		return -ENOMEM;
  	platform_set_drvdata(pdev, clk_data);
@@ -114,7 +114,6 @@ static void clk_mt6735_apmixed_remove(struct platform_device *pdev)
  	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
 
  	mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls), clk_data);
-	mtk_free_clk_data(clk_data);
  }
 
  static const struct of_device_id of_match_mt6735_apmixedsys[] = {
--
Quoted 2 lines

2.47.0

Thanks for the fix!

maintainer Applied
#2 lore raw
In reply to Christophe JAILLET

Quoting Christophe JAILLET (2024-10-25 08:46:08)

Quoted 10 lines

If an error occurs after a successful mtk_alloc_clk_data(), mtk_free_clk_data() should be called, as already done in the .remove() function.

Switch to mtk_devm_alloc_clk_data() in order to fix the memory leak in the probe function, and simplify the remove function.

Fixes 43c04ed79189 ("clk: mediatek: Add drivers for MediaTek MT6735 main clock and reset drivers")

---

Applied to clk-next