[PATCH] thermal/drivers/stm32: Turn the sensor off after the zone is unregistered

Arina Kharlamova via B4 Relay devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Mon Nov 30 14:57:02 PST 2026


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

remove() calls stm_thermal_sensor_off(), which powers the sensor down
and disables its clock. The threaded interrupt requested with
devm_request_threaded_irq() is only freed by devres after remove()
returns. If it runs in that window, stm_thermal_irq_handler() reads and
writes the DTS registers with the clock off and enables the sensor
interrupts again.

Also, when probe fails after the sensor was powered on, nothing turns
it off.

Register the power off as a devres action before the zone and the
interrupt, so it runs after both are released, and drop the call from
remove().

Fixes: 1d6931556073 ("thermal: add stm32 thermal driver")
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/st/stm_thermal.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c
index 46d1db8618e9..77e048e006cb 100644
--- a/drivers/thermal/st/stm_thermal.c
+++ b/drivers/thermal/st/stm_thermal.c
@@ -413,6 +413,11 @@ static int stm_thermal_sensor_off(struct stm_thermal_sensor *sensor)
 	return 0;
 }
 
+static void stm_thermal_sensor_off_action(void *data)
+{
+	stm_thermal_sensor_off(data);
+}
+
 static int stm_thermal_prepare(struct stm_thermal_sensor *sensor)
 {
 	int ret;
@@ -529,6 +534,11 @@ static int stm_thermal_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       stm_thermal_sensor_off_action, sensor);
+	if (ret)
+		return ret;
+
 	sensor->th_dev = devm_thermal_of_zone_register(&pdev->dev, 0,
 						       sensor,
 						       &stm_tz_ops);
@@ -568,7 +578,6 @@ static void stm_thermal_remove(struct platform_device *pdev)
 {
 	struct stm_thermal_sensor *sensor = platform_get_drvdata(pdev);
 
-	stm_thermal_sensor_off(sensor);
 	thermal_remove_hwmon_sysfs(sensor->th_dev);
 }
 

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-d100-f6fab194c9ce

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





More information about the linux-arm-kernel mailing list