mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
  2026-11-19  2:29 ` [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source Yaohan Li
  0 siblings, 2 replies; 4+ 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	[flat|nested] 4+ 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
  2026-11-19  2:29 ` [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source Yaohan Li
  1 sibling, 0 replies; 4+ 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] 4+ messages in thread

* [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source
  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
@ 2026-11-19  2:29 ` Yaohan Li
  2026-11-19 11:11   ` Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Yaohan Li @ 2026-11-19  2:29 UTC (permalink / raw)
  To: miquel.raynal, rafael, daniel.lezcano
  Cc: rui.zhang, lukasz.luba, linux-pm, linux-kernel, edubezval

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: a device without one, or with an invalid
IRQ number, keeps working without overheat detection instead of failing
to probe.

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 source is masked at probe time as well, in case the firmware
left it on.

The handler polls its sensor once per second until the temperature is back
below the hysteresis, and devres waits for it in free_irq().  ->remove()
masks the source and sets a shutdown flag so that the poll 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@gmail.com>

---
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 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 | 69 ++++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 83672f95b011..23f820415e56 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,12 +298,19 @@ 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;
 
+	/*
+	 * Only the variants that describe the overheat interrupt as a DFX
+	 * cause have this source; leave the control register alone on the
+	 * others.
+	 */
+	if (!data->dfx_overheat_irq)
+		return;
+
 	regmap_read(priv->syscon, data->syscon_control1_off, &reg);
 	FIELD_MODIFY(CONTROL1_TSEN_INT_EN, &reg, 0);
 	regmap_write(priv->syscon, data->syscon_control1_off, reg);
@@ -538,7 +546,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 +810,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;
 }
@@ -891,20 +898,16 @@ static int armada_thermal_probe(struct platform_device *pdev)
 	drvdata->data.priv = priv;
 	platform_set_drvdata(pdev, drvdata);
 
+	/*
+	 * The firmware may have left the overheat source enabled.  Keep it
+	 * masked until a handler is in place.
+	 */
+	armada_disable_overheat_interrupt(priv);
+
 	irq = platform_get_irq(pdev, 0);
 	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 +940,29 @@ 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)
+	/*
+	 * The overheat interrupt is optional: a device without one keeps
+	 * working, and an invalid IRQ number must not be requested.
+	 */
+	if (irq <= 0 || !priv->overheat_sensor) {
 		dev_warn(&pdev->dev, "Overheat interrupt not available\n");
+		return 0;
+	}
+
+	/*
+	 * Request the interrupt only now that the thermal zones are
+	 * registered: devres releases what was registered last first, so the
+	 * handler is freed before the zones it updates.  The source stays
+	 * masked until the handler is in place, so the device cannot raise an
+	 * interrupt that nobody handles.
+	 */
+	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);
 
 	return 0;
 }
@@ -948,8 +971,20 @@ 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;
+	}
+
+	/*
+	 * devres frees the interrupt before the thermal zones, so the thread
+	 * is waited for in free_irq().  Mask the source so that no new
+	 * interrupt is raised for a handler that is about to go away, and let
+	 * the poll loop give up instead of keeping ->remove() blocked until
+	 * the sensor cools down.
+	 */
+	WRITE_ONCE(drvdata->data.priv->shutdown, true);
+	armada_disable_overheat_interrupt(drvdata->data.priv);
 }
 
 static struct platform_driver armada_thermal_driver = {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source
  2026-11-19  2:29 ` [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source Yaohan Li
@ 2026-11-19 11:11   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2026-11-19 11:11 UTC (permalink / raw)
  To: Yaohan Li
  Cc: rafael, daniel.lezcano, rui.zhang, lukasz.luba, linux-pm,
	linux-kernel, edubezval

On 19/11/2026 at 10:29:11 +08, Yaohan Li <shunsheng1218@gmail.com> wrote:

> 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: a device without one, or with an invalid
> IRQ number, keeps working without overheat detection instead of failing
> to probe.
>
> 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 source is masked at probe time as well, in case the firmware
> left it on.
>
> The handler polls its sensor once per second until the temperature is back
> below the hysteresis, and devres waits for it in free_irq().  ->remove()
> masks the source and sets a shutdown flag so that the poll 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@gmail.com>
>
> ---
> 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 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 | 69 ++++++++++++++++++++++++--------
>  1 file changed, 52 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
> index 83672f95b011..23f820415e56 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,12 +298,19 @@ 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;
>  
> +	/*
> +	 * Only the variants that describe the overheat interrupt as a DFX
> +	 * cause have this source; leave the control register alone on the
> +	 * others.
> +	 */
> +	if (!data->dfx_overheat_irq)
> +		return;
> +

That's over defensive. This case is unreachable.

>  	regmap_read(priv->syscon, data->syscon_control1_off, &reg);
>  	FIELD_MODIFY(CONTROL1_TSEN_INT_EN, &reg, 0);
>  	regmap_write(priv->syscon, data->syscon_control1_off, reg);
> @@ -538,7 +546,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 +810,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;
>  }
> @@ -891,20 +898,16 @@ static int armada_thermal_probe(struct platform_device *pdev)
>  	drvdata->data.priv = priv;
>  	platform_set_drvdata(pdev, drvdata);
>  
> +	/*
> +	 * The firmware may have left the overheat source enabled.  Keep it
> +	 * masked until a handler is in place.
> +	 */
> +	armada_disable_overheat_interrupt(priv);
> +
>  	irq = platform_get_irq(pdev, 0);
>  	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 +940,29 @@ 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)
> +	/*
> +	 * The overheat interrupt is optional: a device without one keeps
> +	 * working, and an invalid IRQ number must not be requested.

Here you change a bit the behaviour of the driver. ENXIO is a valid
error indeed, but any other negative value may fail the probe. I don't
mind to keep it that way (not failing in case of wrong IRQ), but a line
in the commit log about it is necessary.

> +	 */
> +	if (irq <= 0 || !priv->overheat_sensor) {
>  		dev_warn(&pdev->dev, "Overheat interrupt not available\n");
> +		return 0;
> +	}

I personally don't like early returns when everything is fine. I would
prefer that you just keep the whole irq handling inside an if clause.

> +
> +	/*
> +	 * Request the interrupt only now that the thermal zones are
> +	 * registered: devres releases what was registered last first, so the
> +	 * handler is freed before the zones it updates.  The source stays
> +	 * masked until the handler is in place, so the device cannot raise an
> +	 * interrupt that nobody handles.
> +	 */

This comment is not needed, please drop.

> +	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);
>  
>  	return 0;
>  }
> @@ -948,8 +971,20 @@ 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;
> +	}
> +
> +	/*
> +	 * devres frees the interrupt before the thermal zones, so the thread
> +	 * is waited for in free_irq().  Mask the source so that no new
> +	 * interrupt is raised for a handler that is about to go away, and let
> +	 * the poll loop give up instead of keeping ->remove() blocked until
> +	 * the sensor cools down.
> +	 */

This paragraph is also not needed in my opinion.

> +	WRITE_ONCE(drvdata->data.priv->shutdown, true);
> +	armada_disable_overheat_interrupt(drvdata->data.priv);
>  }
>  
>  static struct platform_driver armada_thermal_driver = {

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19 11:11 UTC | newest]

Thread overview: 4+ 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
2026-11-19  2:29 ` [PATCH v2] thermal/drivers/armada: request the overheat IRQ before enabling the source Yaohan Li
2026-11-19 11:11   ` Miquel Raynal

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®