* [PATCH] thermal: db8500: register the zone before requesting the interrupts
@ 2026-11-17 14:53 Yaohan Li
0 siblings, 0 replies; only message in thread
From: Yaohan Li @ 2026-11-17 14:53 UTC (permalink / raw)
To: rafael, daniel.lezcano; +Cc: rui.zhang, lukasz.luba, linux-pm, linux-kernel
Both threaded handlers call thermal_zone_device_update(th->tz, ...), but
the thermal zone is registered last, after both
devm_request_threaded_irq() calls.
That leaves two windows. During probe an interrupt can be served while
th->tz is still NULL or holds an error pointer. On removal devres runs
in reverse order, so the zone is unregistered and freed before the two
IRQs are released, and a handler that the hardirq has already woken can
then operate on a freed thermal_zone_device.
Register the zone first and request the interrupts afterwards, so devres
releases the IRQs before the zone.
Stopping the PRCMU measurement from .remove() would not be enough on its
own: db8500_thermal_update_config(), which both handlers call, stops the
sensing and starts it again, so a handler still running when .remove()
returns restarts it. Register the stop as a devres action placed between
the zone and the interrupts instead. It then runs after both handlers
have been released and before the zone goes away, and it also covers a
probe failure past that point.
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Prepared against v7.4-rc1-1969-g666539eecdf4.
AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant. The author
reviewed the reasoning and takes responsibility for the content.
This revision registers the thermal zone before the interrupts and puts
the PRCMU stop into a devres action placed between them, so devres
releases both handlers first, then stops the measurement, then
unregisters the zone. A stop issued from .remove() alone would be
undone by a handler still running db8500_thermal_update_config(), which
stops the sensing and starts it again.
Testing: compiled for ARCH=arm with u8500_defconfig (gcc 11.4,
arm-linux-gnueabi). No Ux500 hardware was available, so neither the
normal removal nor the second-IRQ-failure path was exercised.
---
drivers/thermal/db8500_thermal.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c
index 48981247763f..b8f75838cc4d 100644
--- a/drivers/thermal/db8500_thermal.c
+++ b/drivers/thermal/db8500_thermal.c
@@ -148,6 +148,11 @@ static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data)
return IRQ_HANDLED;
}
+static void db8500_thermal_stop_action(void *data)
+{
+ db8500_prcmu_stop_temp_sense();
+}
+
static int db8500_thermal_probe(struct platform_device *pdev)
{
struct db8500_thermal_zone *th = NULL;
@@ -160,6 +165,23 @@ static int db8500_thermal_probe(struct platform_device *pdev)
th->dev = dev;
+ /* register of thermal sensor and get info from DT */
+ th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
+ if (IS_ERR(th->tz)) {
+ dev_err(dev, "register thermal zone sensor failed\n");
+ return PTR_ERR(th->tz);
+ }
+ dev_info(dev, "thermal zone sensor registered\n");
+
+ /*
+ * Registered after the zone and before the interrupts, so devres runs
+ * it after both handlers have been released: a handler cannot restart
+ * the measurement behind our back.
+ */
+ ret = devm_add_action_or_reset(dev, db8500_thermal_stop_action, th);
+ if (ret)
+ return ret;
+
low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
if (low_irq < 0)
return low_irq;
@@ -180,14 +202,6 @@ static int db8500_thermal_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
- /* register of thermal sensor and get info from DT */
- th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
- if (IS_ERR(th->tz)) {
- dev_err(dev, "register thermal zone sensor failed\n");
- return PTR_ERR(th->tz);
- }
- dev_info(dev, "thermal zone sensor registered\n");
-
/* Start measuring at the lowest point */
db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
db8500_thermal_points[0]);
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-17 14:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 14:53 [PATCH] thermal: db8500: register the zone before requesting the interrupts Yaohan Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®