[PATCH v3] thermal/drivers/armada: request the overheat IRQ before enabling the source

From: Yaohan Li

Date: Thu Nov 19 2026 - 23:27:44 EST


armada_thermal_probe() requests the overheat interrupt before it registers
the thermal zones. Devres releases resources in the reverse order, so the
zones are unregistered first and the interrupt is freed afterwards: a
handler that is still running, or that fires in the window between the
two, passes a zone that has already been destroyed to
thermal_zone_device_update().

Request the interrupt after the zone loop instead. The handler is then
freed before the zones it updates, and the interrupt is only requested
when a critical trip point was found, which is the only case in which the
driver has an overheat source to enable.

The interrupt stays optional, as before: apart from -EPROBE_DEFER, an
unavailable or invalid IRQ number does not fail the probe, it only leaves
the device without overheat interrupt handling.

The source has to be enabled after the handler is registered, so
armada_configure_overheat_int() only programs the thresholds now and
armada_thermal_probe() enables the source once the request has succeeded.
A failed request then cannot leave an interrupt enabled that nobody
handles.

The zones are now registered while the source is still masked, so the
driver masks it at probe time on the variants that describe the overheat
interrupt as a DFX cause: a firmware that left it enabled would otherwise
raise an interrupt that nobody handles until the request below. The mask
is released when the request succeeds.

->remove() masks the source and sets a shutdown flag so that the poll loop
gives up instead of keeping the removal blocked until the sensor cools
down.

Fixes: 879d7362d1d0 ("thermal: armada: add overheat interrupt support")
Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>

---
Prepared against v7.4-rc1-1969-g666539eecdf4.

Compile tested only: arm64, aarch64-linux-gnu-gcc 11.4,
CONFIG_ARMADA_THERMAL=y and CONFIG_ARCH_MVEBU=y. No hardware was available,
so the removal path was not exercised and no race injection was run.

AI assistance: prepared with Claude (Anthropic) as a coding assistant; the
author reviewed the reasoning and takes responsibility for the content.

Changes in v3:
- Keep the IRQ handling inside an if clause instead of returning early on
the success path.
- Drop the DFX source guard from armada_disable_overheat_interrupt(); the
check sits at the probe call site instead, where it tells the variants
with a DFX overheat source apart.
- Keep the probe time mask, ahead of the zone registration, so that a
source the firmware left enabled cannot fire before the handler exists.
- Drop the two long comments and the paragraph that restated the existing
poll behaviour.
- Say in the commit log how an unusable IRQ number is handled.

Changes in v2:
- Request the interrupt after the thermal zones are registered instead of
freeing it from ->remove(); Miquel asked for the smaller shape, so the
helper and the stored IRQ number are gone.
- Enable the source only after the handler is registered, so a failed
request cannot leave an interrupt enabled that nobody handles.
- Mask the source at probe time, but only on the variants that describe the
overheat interrupt as a DFX cause.
---
drivers/thermal/armada_thermal.c | 46 ++++++++++++++++++++------------
1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 83672f95b011..859e2f9da1c6 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -68,6 +68,7 @@ struct armada_thermal_priv {
struct thermal_zone_device *overheat_sensor;
int interrupt_source;
int current_channel;
+ bool shutdown;
long current_threshold;
long current_hysteresis;
};
@@ -297,8 +298,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;
@@ -538,7 +538,7 @@ 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));

regmap_read(priv->syscon, priv->data->dfx_irq_cause_off, &dummy);

@@ -802,7 +802,6 @@ static int armada_configure_overheat_int(struct armada_thermal_priv *priv,
armada_set_overheat_thresholds(priv, temperature, 0);
priv->overheat_sensor = tz;
priv->interrupt_source = sensor_id;
- armada_enable_overheat_interrupt(priv);

return 0;
}
@@ -887,6 +886,15 @@ static int armada_thermal_probe(struct platform_device *pdev)

priv->current_channel = -1;
priv->data->init(pdev, priv);
+
+ /*
+ * Mask the source until the handler is registered. The firmware may
+ * have left it enabled, and the zones below are registered before the
+ * interrupt is requested.
+ */
+ if (priv->data->dfx_overheat_irq)
+ armada_disable_overheat_interrupt(priv);
+
drvdata->type = SYSCON;
drvdata->data.priv = priv;
platform_set_drvdata(pdev, drvdata);
@@ -895,16 +903,6 @@ static int armada_thermal_probe(struct platform_device *pdev)
if (irq == -EPROBE_DEFER)
return irq;

- /* The overheat interrupt feature is not mandatory */
- if (irq > 0) {
- ret = devm_request_threaded_irq(&pdev->dev, irq,
- armada_overheat_isr,
- armada_overheat_isr_thread,
- 0, NULL, priv);
- if (ret)
- return ret;
- }
-
/*
* There is one channel for the IC and one per CPU (if any), each
* channel has one sensor.
@@ -937,9 +935,18 @@ static int armada_thermal_probe(struct platform_device *pdev)
armada_configure_overheat_int(priv, tz, sensor->id);
}

- /* Just complain if no overheat interrupt was set up */
- if (!priv->overheat_sensor)
+ if (irq > 0 && priv->overheat_sensor) {
+ ret = devm_request_threaded_irq(&pdev->dev, irq,
+ armada_overheat_isr,
+ armada_overheat_isr_thread,
+ 0, NULL, priv);
+ if (ret)
+ return ret;
+
+ armada_enable_overheat_interrupt(priv);
+ } else {
dev_warn(&pdev->dev, "Overheat interrupt not available\n");
+ }

return 0;
}
@@ -948,8 +955,13 @@ 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;
+ }
+
+ WRITE_ONCE(drvdata->data.priv->shutdown, true);
+ armada_disable_overheat_interrupt(drvdata->data.priv);
}

static struct platform_driver armada_thermal_driver = {
--
2.34.1