diff mbox series

[v2,2/2] thermal: mediatek: change clk_prepare_enable to devm_clk_get_enabled in mtk_thermal_probe

Message ID 20230403164610.3608082-2-void0red@hust.edu.cn
State New
Headers show
Series [v2,1/2] thermal: mediatek: use devm_of_iomap to avoid resource leak in mtk_thermal_probe | expand

Commit Message

Kang Chen April 3, 2023, 4:46 p.m. UTC
use devm_clk_get_enabled to do automatic resource management.

Signed-off-by: Kang Chen <void0red@hust.edu.cn>
---
I'm not quite sure if this function should return 0 when
devm_thermal_add_hwmon_sysfs occurs error. So I keep it.

 drivers/thermal/mediatek/auxadc_thermal.c | 25 ++++++++---------------
 1 file changed, 8 insertions(+), 17 deletions(-)

Comments

Kang Chen April 10, 2023, 3:46 a.m. UTC | #1
> -----原始邮件-----
> 发件人: "Kang Chen" <void0red@hust.edu.cn>
> 发送时间: 2023-04-04 00:46:10 (星期二)
> 收件人: daniel.lezcano@linaro.org
> 抄送: amitk@kernel.org, angelogioacchino.delregno@collabora.com, bchihi@baylibre.com, daniel@makrotopia.org, dzm91@hust.edu.cn, error27@gmail.com, henry.yen@mediatek.com, hust-os-kernel-patches@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, matthias.bgg@gmail.com, rafael@kernel.org, rdunlap@infradead.org, rui.zhang@intel.com, void0red@gmail.com, void0red@hust.edu.cn
> 主题: [PATCH v2 2/2] thermal: mediatek: change clk_prepare_enable to devm_clk_get_enabled in mtk_thermal_probe
> 
> use devm_clk_get_enabled to do automatic resource management.
> 
> Signed-off-by: Kang Chen <void0red@hust.edu.cn>
> ---
> I'm not quite sure if this function should return 0 when
> devm_thermal_add_hwmon_sysfs occurs error. So I keep it.
> 
>  drivers/thermal/mediatek/auxadc_thermal.c | 25 ++++++++---------------
>  1 file changed, 8 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index df5e2e354408..5baec2c08ebc 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
> @@ -1178,16 +1178,16 @@ static int mtk_thermal_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ret = clk_prepare_enable(mt->clk_auxadc);
> -	if (ret) {
> +	ret = devm_clk_get_enabled(&pdev->dev, mt->clk_auxadc);
> +	if (IS_ERR(ret)) {
>  		dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
> -		return ret;
> +		return PTR_ERR(ret);
>  	}
>  
> -	ret = clk_prepare_enable(mt->clk_peri_therm);
> -	if (ret) {
> +	ret = devm_clk_get_enabled(&pdev->dev, mt->clk_peri_therm);
> +	if (IS_ERR(ret)) {
>  		dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
> -		goto err_disable_clk_auxadc;
> +		return PTR_ERR(ret);
>  	}
>  
>  	if (mt->conf->version != MTK_THERMAL_V1) {
> @@ -1211,23 +1211,14 @@ static int mtk_thermal_probe(struct platform_device *pdev)
>  
>  	tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt,
>  					      &mtk_thermal_ops);
> -	if (IS_ERR(tzdev)) {
> -		ret = PTR_ERR(tzdev);
> -		goto err_disable_clk_peri_therm;
> -	}
> +	if (IS_ERR(tzdev))
> +		return PTR_ERR(tzdev);
>  
>  	ret = devm_thermal_add_hwmon_sysfs(tzdev);
>  	if (ret)
>  		dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");
>  
>  	return 0;
> -
> -err_disable_clk_peri_therm:
> -	clk_disable_unprepare(mt->clk_peri_therm);
> -err_disable_clk_auxadc:
> -	clk_disable_unprepare(mt->clk_auxadc);
> -
> -	return ret;
>  }
>  
>  static int mtk_thermal_remove(struct platform_device *pdev)
> -- 
> 2.34.1

ping?
Daniel Lezcano April 10, 2023, 7:42 p.m. UTC | #2
On 10/04/2023 05:46, 陈康 wrote:

[ ... ]

>>   static int mtk_thermal_remove(struct platform_device *pdev)
>> -- 
>> 2.34.1
> 
> ping?

Did you check the 'mtk_thermal_remove' function ?
diff mbox series

Patch

diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index df5e2e354408..5baec2c08ebc 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -1178,16 +1178,16 @@  static int mtk_thermal_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(mt->clk_auxadc);
-	if (ret) {
+	ret = devm_clk_get_enabled(&pdev->dev, mt->clk_auxadc);
+	if (IS_ERR(ret)) {
 		dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
-		return ret;
+		return PTR_ERR(ret);
 	}
 
-	ret = clk_prepare_enable(mt->clk_peri_therm);
-	if (ret) {
+	ret = devm_clk_get_enabled(&pdev->dev, mt->clk_peri_therm);
+	if (IS_ERR(ret)) {
 		dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
-		goto err_disable_clk_auxadc;
+		return PTR_ERR(ret);
 	}
 
 	if (mt->conf->version != MTK_THERMAL_V1) {
@@ -1211,23 +1211,14 @@  static int mtk_thermal_probe(struct platform_device *pdev)
 
 	tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt,
 					      &mtk_thermal_ops);
-	if (IS_ERR(tzdev)) {
-		ret = PTR_ERR(tzdev);
-		goto err_disable_clk_peri_therm;
-	}
+	if (IS_ERR(tzdev))
+		return PTR_ERR(tzdev);
 
 	ret = devm_thermal_add_hwmon_sysfs(tzdev);
 	if (ret)
 		dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");
 
 	return 0;
-
-err_disable_clk_peri_therm:
-	clk_disable_unprepare(mt->clk_peri_therm);
-err_disable_clk_auxadc:
-	clk_disable_unprepare(mt->clk_auxadc);
-
-	return ret;
 }
 
 static int mtk_thermal_remove(struct platform_device *pdev)