* [PATCH] thermal/drivers/armada: free the overheat IRQ before the zones are gone
@ 2026-11-18 7:23 Yaohan Li
2026-11-18 9:29 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Yaohan Li @ 2026-11-18 7:23 UTC (permalink / raw)
To: miquel.raynal, rafael, daniel.lezcano
Cc: rui.zhang, lukasz.luba, linux-pm, linux-kernel, edubezval
The overheat interrupt is requested before the thermal zones are
registered, so devres releases the zones first and the interrupt
afterwards. armada_overheat_isr_thread() calls
thermal_zone_device_update() on priv->overheat_sensor, which by then has
been unregistered and freed, and thermal_zone_device_update() locks the
zone mutex unconditionally.
The handler also polls the sensor once per second until the temperature
drops below the threshold. If that poll is still running when the
device goes away, free_irq() waits for it and the removal is blocked for
as long as the sensor stays hot.
The same handler runs while priv->overheat_sensor is still NULL, because
the interrupt is requested before the zones exist and a spurious
interrupt in that window passes a NULL zone to
thermal_zone_device_update().
Move the teardown into armada_thermal_quiesce_irq(), which disables the
interrupt, frees it and tells the poll loop to give up, and call it from
->remove(). The same helper is called from the probe rollback once the
interrupt has been requested: the driver core does not run ->remove()
for a probe that fails, while devres still frees the zones and the
private data of an interface whose handler is registered.
Read the zone once at the top of the thread and bail out when it is not
published yet or the driver is shutting down, and reuse that pointer for
both thermal_zone_device_update() calls.
Fixes: 879d7362d1d0 ("thermal: armada: add overheat interrupt support")
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.
Testing: compile tested only (arm64, gcc 11.4). No Armada hardware was
available, so neither the removal race nor the poll loop were run.
drivers/thermal/armada_thermal.c | 66 +++++++++++++++++++++++++++-----
1 file changed, 56 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 83672f95b011..72261338d744 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -68,6 +68,8 @@ struct armada_thermal_priv {
struct thermal_zone_device *overheat_sensor;
int interrupt_source;
int current_channel;
+ int irq;
+ bool shutdown;
long current_threshold;
long current_hysteresis;
};
@@ -297,8 +299,7 @@ static void armada_enable_overheat_interrupt(struct armada_thermal_priv *priv)
regmap_write(priv->syscon, data->syscon_control1_off, reg);
}
-static void __maybe_unused
-armada_disable_overheat_interrupt(struct armada_thermal_priv *priv)
+static void armada_disable_overheat_interrupt(struct armada_thermal_priv *priv)
{
struct armada_thermal_data *data = priv->data;
u32 reg;
@@ -517,14 +518,22 @@ static irqreturn_t armada_overheat_isr(int irq, void *blob)
static irqreturn_t armada_overheat_isr_thread(int irq, void *blob)
{
struct armada_thermal_priv *priv = blob;
+ struct thermal_zone_device *zone;
int low_threshold = priv->current_threshold - priv->current_hysteresis;
int temperature;
u32 dummy;
int ret;
+ /*
+ * The interrupt is requested before the thermal zones are
+ * registered, so overheat_sensor can still be NULL here.
+ */
+ zone = READ_ONCE(priv->overheat_sensor);
+ if (READ_ONCE(priv->shutdown) || !zone)
+ goto enable_irq;
+
/* Notify the core in thread context */
- thermal_zone_device_update(priv->overheat_sensor,
- THERMAL_EVENT_UNSPECIFIED);
+ thermal_zone_device_update(zone, THERMAL_EVENT_UNSPECIFIED);
/*
* The overheat interrupt must be cleared by reading the DFX interrupt
@@ -538,13 +547,15 @@ static irqreturn_t armada_overheat_isr_thread(int irq, void *blob)
mutex_unlock(&priv->update_lock);
if (ret)
goto enable_irq;
- } while (temperature >= low_threshold);
+ } while (temperature >= low_threshold && !READ_ONCE(priv->shutdown));
+
+ if (READ_ONCE(priv->shutdown))
+ goto enable_irq;
regmap_read(priv->syscon, priv->data->dfx_irq_cause_off, &dummy);
/* Notify the thermal core that the temperature is acceptable again */
- thermal_zone_device_update(priv->overheat_sensor,
- THERMAL_EVENT_UNSPECIFIED);
+ thermal_zone_device_update(zone, THERMAL_EVENT_UNSPECIFIED);
enable_irq:
enable_irq(irq);
@@ -807,6 +818,29 @@ static int armada_configure_overheat_int(struct armada_thermal_priv *priv,
return 0;
}
+/*
+ * Stop the overheat interrupt for good. Both ->remove() and the probe
+ * rollback after the interrupt was requested go through here, so that a
+ * failed probe cannot leave a handler behind either.
+ */
+static void armada_thermal_quiesce_irq(struct armada_thermal_priv *priv)
+{
+ if (priv->irq <= 0)
+ return;
+
+ /*
+ * devres unregisters the thermal zones before it frees the
+ * interrupt, because the zones were registered after it. Stop the
+ * handler here so that it cannot touch a zone that is already gone.
+ * Tell the poll loop to give up as well, or free_irq() waits for the
+ * sensor to cool down before the removal can finish.
+ */
+ WRITE_ONCE(priv->shutdown, true);
+ armada_disable_overheat_interrupt(priv);
+ devm_free_irq(priv->dev, priv->irq, priv);
+ priv->irq = 0;
+}
+
static int armada_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *tz;
@@ -903,6 +937,8 @@ static int armada_thermal_probe(struct platform_device *pdev)
0, NULL, priv);
if (ret)
return ret;
+
+ priv->irq = irq;
}
/*
@@ -912,8 +948,10 @@ static int armada_thermal_probe(struct platform_device *pdev)
for (sensor_id = 0; sensor_id <= priv->data->cpu_nr; sensor_id++) {
sensor = devm_kzalloc_obj(&pdev->dev,
struct armada_thermal_sensor);
- if (!sensor)
- return -ENOMEM;
+ if (!sensor) {
+ ret = -ENOMEM;
+ goto err_irq;
+ }
/* Register the sensor */
sensor->priv = priv;
@@ -942,14 +980,22 @@ static int armada_thermal_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "Overheat interrupt not available\n");
return 0;
+
+err_irq:
+ armada_thermal_quiesce_irq(priv);
+ return ret;
}
static void armada_thermal_exit(struct platform_device *pdev)
{
struct armada_drvdata *drvdata = platform_get_drvdata(pdev);
- if (drvdata->type == LEGACY)
+ if (drvdata->type == LEGACY) {
thermal_zone_device_unregister(drvdata->data.tz);
+ return;
+ }
+
+ armada_thermal_quiesce_irq(drvdata->data.priv);
}
static struct platform_driver armada_thermal_driver = {
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] thermal/drivers/armada: free the overheat IRQ before the zones are gone
2026-11-18 7:23 [PATCH] thermal/drivers/armada: free the overheat IRQ before the zones are gone Yaohan Li
@ 2026-11-18 9:29 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-11-18 9:29 UTC (permalink / raw)
To: Yaohan Li
Cc: rafael, daniel.lezcano, rui.zhang, lukasz.luba, linux-pm,
linux-kernel, edubezval
On 18/11/2026 at 15:23:39 +08, Yaohan Li <shunsheng1218@gmail.com> wrote:
> The overheat interrupt is requested before the thermal zones are
> registered, so devres releases the zones first and the interrupt
> afterwards. armada_overheat_isr_thread() calls
> thermal_zone_device_update() on priv->overheat_sensor, which by then has
> been unregistered and freed, and thermal_zone_device_update() locks the
> zone mutex unconditionally.
>
> The handler also polls the sensor once per second until the temperature
> drops below the threshold. If that poll is still running when the
> device goes away, free_irq() waits for it and the removal is blocked for
> as long as the sensor stays hot.
>
> The same handler runs while priv->overheat_sensor is still NULL, because
> the interrupt is requested before the zones exist and a spurious
> interrupt in that window passes a NULL zone to
> thermal_zone_device_update().
>
> Move the teardown into armada_thermal_quiesce_irq(), which disables the
> interrupt, frees it and tells the poll loop to give up, and call it from
> ->remove(). The same helper is called from the probe rollback once the
> interrupt has been requested: the driver core does not run ->remove()
> for a probe that fails, while devres still frees the zones and the
> private data of an interface whose handler is registered.
>
> Read the zone once at the top of the thread and bail out when it is not
> published yet or the driver is shutting down, and reuse that pointer for
> both thermal_zone_device_update() calls.
>
> Fixes: 879d7362d1d0 ("thermal: armada: add overheat interrupt support")
> Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
Your solution is over-engineered. For a case simple like that, you would
need to just move the IRQ registration (not the get_irq()) after the
zones registration.
Maybe you need a shutdown boolean as well, but clearly not all the extra
complexity you are trying to add.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 9:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 7:23 [PATCH] thermal/drivers/armada: free the overheat IRQ before the zones are gone Yaohan Li
2026-11-18 9:29 ` Miquel Raynal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.