From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Yaohan Li <shunsheng1218@gmail.com>
Cc: rafael@kernel.org, daniel.lezcano@kernel.org,
rui.zhang@intel.com, lukasz.luba@arm.com,
geert+renesas@glider.be, magnus.damm@gmail.com,
linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] thermal: rcar_gen3: quiesce the interrupt source before releasing it
Date: Wed, 18 Nov 2026 10:31:04 +0100 [thread overview]
Message-ID: <20261118093104.GA2548353@ragnatech.se> (raw)
In-Reply-To: <20261117145348.1092528-1-shunsheng1218@gmail.com>
Hi Yaohan,
Thanks for your work.
On 2026-11-17 22:53:48 +0800, Yaohan Li wrote:
> rcar_gen3_thermal_remove() only drops the runtime PM reference. The two
> threaded interrupts are left to devres, which releases them after the
> TSC objects and the thermal zones have already been freed, and the
> device keeps raising interrupts because nothing clears REG_GEN3_IRQEN.
>
> rcar_gen3_thermal_irq() walks priv->tscs[i], reads REG_GEN3_IRQSTR
> through tsc->base and calls thermal_zone_device_update(tsc->zone), so a
> handler that the hardirq has already woken can run after those objects
> are gone.
>
> Disable the interrupt source for every TSC first, then release the
> interrupt handlers, and only then drop the runtime PM reference.
> REG_GEN3_IRQEN is only ever written by rcar_gen3_thermal_init(); a
> concurrent set_trips() writes REG_GEN3_IRQMSK alone, so it cannot undo
> the disable.
>
> Remember the interrupt numbers that were successfully requested, so that
> the partial-probe path, which also ends in .remove(), only releases what
> was actually registered.
Could this be re-written by a human to describe they "why" and not the
"how"?
>
> 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.
>
> This revision also clears REG_GEN3_IRQEN for every TSC before the
> handlers are released. rcar_gen3_thermal_init() is the only writer of
> IRQEN; set_trips() writes IRQMSK only, so a concurrent trip update
> cannot re-enable the interrupt source.
>
> Testing: compile tested only (arm64, gcc 11.4). No R-Car hardware was
> available. The partial-probe path that also ends in .remove() was not
> exercised.
> ---
> drivers/thermal/renesas/rcar_gen3_thermal.c | 25 +++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/thermal/renesas/rcar_gen3_thermal.c b/drivers/thermal/renesas/rcar_gen3_thermal.c
> index 9c64cbc2ee67..35bb49915a75 100644
> --- a/drivers/thermal/renesas/rcar_gen3_thermal.c
> +++ b/drivers/thermal/renesas/rcar_gen3_thermal.c
> @@ -110,6 +110,8 @@ struct rcar_gen3_thermal_priv {
> int ptat[3];
> int tj_t;
> const struct rcar_thermal_info *info;
> + int irqs[2];
> + unsigned int num_irqs;
> };
>
> static inline u32 rcar_gen3_thermal_read(struct rcar_gen3_thermal_tsc *tsc,
> @@ -468,7 +470,28 @@ MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids);
>
> 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;
> +
> + /*
> + * Disable the interrupt source while the device is still runtime
> + * resumed. REG_GEN3_IRQEN is only ever written by
> + * rcar_gen3_thermal_init(); a concurrent set_trips() writes
> + * REG_GEN3_IRQMSK alone, so it cannot re-enable the source here.
> + */
> + for (i = 0; i < priv->num_tscs; i++) {
Move the loop variable declaration here.
> + rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQEN, 0);
> + rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQMSK, 0);
> + }
> +
> + /*
> + * Release the interrupts before the TSCs and zones are freed:
> + * free_irq() waits for an executing threaded handler, and the handler
> + * dereferences both priv->tscs[i] and priv->tscs[i]->zone.
> + */
> + for (i = 0; i < priv->num_irqs; i++)
Can't you store a negative error code in riv->irqs[] to indicate no IRQ
and avoid adding the booking variable num_irqs? One variable can never
go out of sync.
While at it you could create a new define for the maximum number of
IRQ's and replace the loop limit in rcar_gen3_thermal_request_irqs() and
the number of elements in irqs[].
> + devm_free_irq(dev, priv->irqs[i], priv);
Why free it and just not sync the interrupt?
>
> pm_runtime_put(dev);
> pm_runtime_disable(dev);
> @@ -504,6 +527,8 @@ static int rcar_gen3_thermal_request_irqs(struct rcar_gen3_thermal_priv *priv,
> IRQF_ONESHOT, irqname, priv);
> if (ret)
> return ret;
> +
> + priv->irqs[priv->num_irqs++] = irq;
> }
>
> return 0;
> --
> 2.34.1
>
--
Kind Regards,
Niklas Söderlund
prev parent reply other threads:[~2026-11-18 9:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:53 [PATCH] thermal: rcar_gen3: quiesce the interrupt source before releasing it Yaohan Li
2026-11-18 9:31 ` Niklas Söderlund [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118093104.GA2548353@ragnatech.se \
--to=niklas.soderlund@ragnatech.se \
--cc=daniel.lezcano@kernel.org \
--cc=geert+renesas@glider.be \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=magnus.damm@gmail.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=shunsheng1218@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.