[PATCH v4 3/3] thermal: rcar_gen3: do not enable the interrupts before the zones exist
From: Yaohan Li
Date: Tue Nov 24 2026 - 22:03:52 EST
rcar_gen3_thermal_probe() requests the interrupt handlers before the
sensors are initialised. Once num_tscs is set, the handler can access
the sensor registers while sensor initialisation and thermal zone
registration are still in progress.
The handler checks whether tsc->zone is NULL, but this does not prevent
it from accessing the sensor registers during initialisation. Masking
the device interrupt sources alone does not prevent delivery of an
interrupt that is already pending.
Request the interrupts with IRQF_NO_AUTOEN, so that the handlers cannot
run until the driver enables them, and initialise every sensor before
the request. Enable the interrupts and their sources only after all
the thermal zones are registered.
rcar_gen3_thermal_resume() re-initialises the sensors and the sources;
the enable state of the interrupt itself is left to probe.
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_ARCH_RENESAS and CONFIG_RCAR_GEN3_THERMAL.
AI assistance: prepared with Claude (Anthropic) as a coding assistant; the
author reviewed the reasoning and takes responsibility for the content.
---
drivers/thermal/renesas/rcar_gen3_thermal.c | 53 ++++++++++++++-------
1 file changed, 37 insertions(+), 16 deletions(-)
diff --git a/drivers/thermal/renesas/rcar_gen3_thermal.c b/drivers/thermal/renesas/rcar_gen3_thermal.c
index 37348f4413b6..e6682c5759aa 100644
--- a/drivers/thermal/renesas/rcar_gen3_thermal.c
+++ b/drivers/thermal/renesas/rcar_gen3_thermal.c
@@ -326,8 +326,7 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv)
return true;
}
-static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
- struct rcar_gen3_thermal_tsc *tsc)
+static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_tsc *tsc)
{
u32 reg_val;
@@ -337,11 +336,9 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
usleep_range(1000, 2000);
+ rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN, 0);
rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0);
rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0);
- if (priv->ops.set_trips)
- rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN,
- IRQ_TEMPD1 | IRQ_TEMP2);
reg_val = rcar_gen3_thermal_read(tsc, REG_GEN3_THCTR);
reg_val |= THCTR_THSST;
@@ -350,6 +347,15 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv,
usleep_range(1000, 2000);
}
+static void rcar_gen3_thermal_enable_sources(struct rcar_gen3_thermal_priv *priv)
+{
+ unsigned int i;
+
+ for (i = 0; i < priv->num_tscs; i++)
+ rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQEN,
+ IRQ_TEMPD1 | IRQ_TEMP2);
+}
+
static const struct rcar_gen3_thermal_fuse_info rcar_gen3_thermal_fuse_info_gen3 = {
.ptat = { REG_GEN3_PTAT1, REG_GEN3_PTAT2, REG_GEN3_PTAT3 },
.thcode = { REG_GEN3_THCODE1, REG_GEN3_THCODE2, REG_GEN3_THCODE3 },
@@ -523,7 +529,8 @@ static int rcar_gen3_thermal_request_irqs(struct rcar_gen3_thermal_priv *priv,
ret = devm_request_threaded_irq(dev, irq, NULL,
rcar_gen3_thermal_irq,
- IRQF_ONESHOT, irqname, priv);
+ IRQF_ONESHOT | IRQF_NO_AUTOEN,
+ irqname, priv);
if (ret)
goto release;
@@ -555,9 +562,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
priv->info = of_device_get_match_data(dev);
platform_set_drvdata(pdev, priv);
- if (rcar_gen3_thermal_request_irqs(priv, pdev))
- priv->ops.set_trips = NULL;
-
pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
@@ -596,10 +600,20 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
rcar_gen3_thermal_shared_coefs(priv);
for (i = 0; i < priv->num_tscs; i++) {
- struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
+ rcar_gen3_thermal_init(priv->tscs[i]);
+ rcar_gen3_thermal_tsc_coefs(priv, priv->tscs[i]);
+ }
- rcar_gen3_thermal_init(priv, tsc);
- rcar_gen3_thermal_tsc_coefs(priv, tsc);
+ /*
+ * The handler walks the sensor array, so every sensor has to be
+ * initialised before the request. IRQF_NO_AUTOEN keeps the
+ * handlers from running until the zones exist.
+ */
+ if (rcar_gen3_thermal_request_irqs(priv, pdev))
+ priv->ops.set_trips = NULL;
+
+ for (i = 0; i < priv->num_tscs; i++) {
+ struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
zone = devm_thermal_of_zone_register(dev, i, tsc, &priv->ops);
if (IS_ERR(zone)) {
@@ -620,6 +634,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
dev_info(dev, "Sensor %u: Loaded\n", i);
}
+ if (priv->ops.set_trips) {
+ for (i = 0; i < priv->num_irqs; i++)
+ enable_irq(priv->irqs[i]);
+
+ rcar_gen3_thermal_enable_sources(priv);
+ }
+
return 0;
error_unregister:
@@ -633,11 +654,11 @@ static int rcar_gen3_thermal_resume(struct device *dev)
struct rcar_gen3_thermal_priv *priv = dev_get_drvdata(dev);
unsigned int i;
- for (i = 0; i < priv->num_tscs; i++) {
- struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
+ for (i = 0; i < priv->num_tscs; i++)
+ rcar_gen3_thermal_init(priv->tscs[i]);
- rcar_gen3_thermal_init(priv, tsc);
- }
+ if (priv->ops.set_trips)
+ rcar_gen3_thermal_enable_sources(priv);
return 0;
}
--
2.34.1