[PATCH] thermal/drivers/imx8mm: Keep the clock on until the zones are unregistered

Arina Kharlamova via B4 Relay devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Sat Nov 28 23:31:13 PST 2026


From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>

The thermal zones are registered with devm_thermal_of_zone_register(),
but the TMU clock is enabled by hand and disabled in remove(). devres
unregisters the zones only after remove() has returned, so in that
window the polling work or a sysfs read of the temperature can still
call tmu_get_temp() and read TRITSR with the clock gated. The same
happens on the probe error path after the zones are registered.

Get the clock with devm_clk_get_enabled(). It is acquired before the
zones, so devres disables it after they are gone, and the manual
disables in remove() and on the error path can go.

Fixes: 5eed800a6811 ("thermal: imx8mm: Add support for i.MX8MM thermal monitoring unit")
Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
Found by checks derived from the spec2patch kernel API specifications,
with the help of an AI coding assistant (Claude); I reviewed the
analysis and the fix.
---
 drivers/thermal/imx8mm_thermal.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
index 8cf9d554a218..a2fed7076b4a 100644
--- a/drivers/thermal/imx8mm_thermal.c
+++ b/drivers/thermal/imx8mm_thermal.c
@@ -310,17 +310,11 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
 	if (IS_ERR(tmu->base))
 		return PTR_ERR(tmu->base);
 
-	tmu->clk = devm_clk_get(&pdev->dev, NULL);
+	tmu->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(tmu->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(tmu->clk),
 				     "failed to get tmu clock\n");
 
-	ret = clk_prepare_enable(tmu->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to enable tmu clock: %d\n", ret);
-		return ret;
-	}
-
 	/* disable the monitor during initialization */
 	imx8mm_tmu_enable(tmu, false);
 
@@ -335,7 +329,7 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev,
 				"failed to register thermal zone sensor[%d]: %d\n",
 				i, ret);
-			goto disable_clk;
+			return ret;
 		}
 		tmu->sensors[i].hw_id = i;
 
@@ -346,7 +340,7 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
 
 	ret = imx8mm_tmu_probe_set_calib(pdev, tmu);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	/* enable all the probes for V2 TMU */
 	if (tmu->socdata->version == TMU_VER2)
@@ -356,10 +350,6 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
 	imx8mm_tmu_enable(tmu, true);
 
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(tmu->clk);
-	return ret;
 }
 
 static void imx8mm_tmu_remove(struct platform_device *pdev)
@@ -369,7 +359,6 @@ static void imx8mm_tmu_remove(struct platform_device *pdev)
 	/* disable TMU */
 	imx8mm_tmu_enable(tmu, false);
 
-	clk_disable_unprepare(tmu->clk);
 	platform_set_drvdata(pdev, NULL);
 }
 

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-d97-ac7239aae4de

Best regards,
--  
Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>





More information about the linux-arm-kernel mailing list