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

Kang Chen void0red at hust.edu.cn
Mon Apr 3 09:46:10 PDT 2023


use devm_clk_get_enabled to do automatic resource management.

Signed-off-by: Kang Chen <void0red at 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




More information about the Linux-mediatek mailing list