Re: [PATCH v4 2/3] thermal: rcar_gen3: release the interrupt handlers from ->remove()
From: Niklas Söderlund
Date: Wed Nov 25 2026 - 02:33:53 EST
Hi Yaohan,
Thanks for your work.
On 2026-11-25 11:03:26 +0800, Yaohan Li wrote:
> The interrupt handlers are requested before the thermal zones, and
> devres releases the managed resources in the reverse order, so the
> handlers outlive the zones they report to. The handler walks every
> sensor and calls thermal_zone_device_update() through tsc->zone, which
> is not cleared when the zone is unregistered. Masking the interrupt
> sources neither waits for a threaded handler that is already running
> nor removes the action.
>
> Release the handlers from ->remove(), which runs before the runtime PM
> reference is dropped and before devres unregisters the zones.
> free_irq() also waits for a running handler, and after it returns the
> handler cannot be invoked again.
>
> Record the interrupt numbers as they are requested, so that a partial
> request is undone as well: if the second handler cannot be registered,
> the first one is released and the driver falls back to polling, as
> before.
>
> 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 | 38 ++++++++++++++++++---
> 1 file changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/renesas/rcar_gen3_thermal.c b/drivers/thermal/renesas/rcar_gen3_thermal.c
> index a96f02d4a8ad..37348f4413b6 100644
> --- a/drivers/thermal/renesas/rcar_gen3_thermal.c
> +++ b/drivers/thermal/renesas/rcar_gen3_thermal.c
> @@ -107,6 +107,8 @@ struct rcar_gen3_thermal_priv {
> struct rcar_gen3_thermal_tsc *tscs[TSC_MAX_NUM];
> struct thermal_zone_device_ops ops;
> unsigned int num_tscs;
> + int irqs[2];
What happened to RCAR_GEN3_THERMAL_MAX_IRQ ?
Please stop thorowing this code at an LLM it comes up with new code
ignore past ideas.
> + unsigned int num_irqs;
> int ptat[3];
> int tj_t;
> const struct rcar_thermal_info *info;
> @@ -466,9 +468,25 @@ static const struct of_device_id rcar_gen3_thermal_dt_ids[] = {
> };
> MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids);
>
> +static void rcar_gen3_thermal_free_irqs(struct device *dev,
> + struct rcar_gen3_thermal_priv *priv)
> +{
> + while (priv->num_irqs)
Please use a for loop not modifyig priv->num_irqs, this looks dangerous.
> + devm_free_irq(dev, priv->irqs[--priv->num_irqs], priv);
> +}
> +
> static void rcar_gen3_thermal_remove(struct platform_device *pdev)
> {
> + struct rcar_gen3_thermal_priv *priv = platform_get_drvdata(pdev);
> struct device *dev = &pdev->dev;
> + unsigned int i;
> +
> + for (i = 0; i < priv->num_tscs; i++) {
Declare loop variable in for loop, where possible.
> + rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQEN, 0);
> + rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQMSK, 0);
> + }
> +
> + rcar_gen3_thermal_free_irqs(dev, priv);
>
> pm_runtime_put(dev);
> pm_runtime_disable(dev);
> @@ -491,22 +509,32 @@ static int rcar_gen3_thermal_request_irqs(struct rcar_gen3_thermal_priv *priv,
>
> for (i = 0; i < 2; i++) {
> irq = platform_get_irq_optional(pdev, i);
> - if (irq < 0)
> - return irq;
> + if (irq < 0) {
> + ret = irq;
> + goto release;
> + }
This changes the behavior of the driver...
Please stop using an LLM to code this. As you don't have hardware to
test with throwing LLM spaghetti over the wall and see if it sticks is
getting tedious. Please read, understand and write the code yourself as
coding for gear you can't test is hard.
I will not review another set of LLM slop, especially as the good parts
like RCAR_GEN3_THERMAL_MAX_IRQ are dropped between revisions.
Nacked-by: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx>
>
> irqname = devm_kasprintf(dev, GFP_KERNEL, "%s:ch%d",
> dev_name(dev), i);
> - if (!irqname)
> - return -ENOMEM;
> + if (!irqname) {
> + ret = -ENOMEM;
> + goto release;
> + }
>
> ret = devm_request_threaded_irq(dev, irq, NULL,
> rcar_gen3_thermal_irq,
> IRQF_ONESHOT, irqname, priv);
> if (ret)
> - return ret;
> + goto release;
> +
> + priv->irqs[priv->num_irqs++] = irq;
> }
>
> return 0;
> +
> +release:
> + rcar_gen3_thermal_free_irqs(dev, priv);
> + return ret;
> }
>
> static int rcar_gen3_thermal_probe(struct platform_device *pdev)
> --
> 2.34.1
>
--
Kind Regards,
Niklas Söderlund