From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Lee Jones <lee@kernel.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Yaohan Li <shunsheng1218@gmail.com>
Subject: Re: [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove
Date: Fri, 4 Dec 2026 18:15:28 +0100 [thread overview]
Message-ID: <20261204171528.GA3999746@ragnatech.se> (raw)
In-Reply-To: <20261203195529.3063246-7-lee@kernel.org>
Hi Lee,
Thanks for your work.
On 2026-12-03 19:54:17 +0000, Lee Jones wrote:
> rcar_thermal_probe() requests shared IRQs via devm_request_irq(), so
> rcar_thermal_irq() remains active during rcar_thermal_remove() until
> devres teardown runs after the remove callback returns. Because
> rcar_thermal_irq() drops common->lock before queueing priv->work, an
> in-flight interrupt can re-queue the delayed work after
> cancel_delayed_work_sync() has returned, triggering a use-after-free
> after devres frees priv.
>
> Record the requested IRQ numbers in struct rcar_thermal_common and
> explicitly release them with devm_free_irq() in rcar_thermal_remove()
> before cancelling delayed work, disabling hardware interrupts, and
> dropping runtime PM.
>
> Fixes: e0a5172e9eec ("thermal: rcar: add interrupt support")
> Closes: https://sashiko.dev/#/bug/linux-45588606-8892-47eb-8398-6b410ae17278
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/thermal/renesas/rcar_thermal.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c
> index af6d09a75bb6..3e02b16084b4 100644
> --- a/drivers/thermal/renesas/rcar_thermal.c
> +++ b/drivers/thermal/renesas/rcar_thermal.c
> @@ -39,11 +39,15 @@
> /* THSSR */
> #define CTEMP 0x3f
>
> +#define RCAR_THERMAL_MAX_IRQS 2
> +
> struct rcar_thermal_common {
> void __iomem *base;
> struct device *dev;
> struct list_head head;
> spinlock_t lock;
> + int irqs[RCAR_THERMAL_MAX_IRQS];
> + unsigned int nirqs;
> };
>
> struct rcar_thermal_chip {
> @@ -377,9 +381,15 @@ static void rcar_thermal_remove(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct rcar_thermal_priv *priv;
Would not a call to disable_delayed_work_sync() here complete/cancel any
in-flight top-half of the interrupt handler and prevent any new ones
from being scheduled?
Then calling rcar_thermal_irq_disable() would prevent any new bottom
half interrupts and we could led devres clean up?
There is some work in progress for this issue already [1], but I'm not
sure Yaohan was planing to continue it as he had no hardware to test on.
Adding him to CC.
1. https://lore.kernel.org/linux-renesas-soc/20261118072321.1259639-1-shunsheng1218@gmail.com/
>
> - rcar_thermal_for_each_priv(priv, common) {
> + rcar_thermal_for_each_priv(priv, common)
> rcar_thermal_irq_disable(priv);
> +
> + for (unsigned int i = 0; i < common->nirqs; i++)
> + devm_free_irq(dev, common->irqs[i], common);
> +
> + rcar_thermal_for_each_priv(priv, common) {
> cancel_delayed_work_sync(&priv->work);
> + rcar_thermal_irq_disable(priv);
> if (priv->chip->use_of_thermal)
> thermal_remove_hwmon_sysfs(priv->zone);
> else
> @@ -444,10 +454,16 @@ static int rcar_thermal_probe(struct platform_device *pdev)
> idle = 0; /* polling delay is not needed */
> }
>
> + if (common->nirqs >= RCAR_THERMAL_MAX_IRQS) {
> + ret = -EINVAL;
> + goto error_unregister;
> + }
> +
> ret = devm_request_irq(dev, irq, rcar_thermal_irq,
> IRQF_SHARED, dev_name(dev), common);
> if (ret)
> goto error_unregister;
> + common->irqs[common->nirqs++] = irq;
>
> /* update ENR bits */
> if (chip->irq_per_ch)
> --
> 2.56.1.911.g883d8bcb20-goog
>
--
Kind Regards,
Niklas Söderlund
next prev parent reply other threads:[~2026-12-04 17:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:54 [PATCH 00/10] thermal: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 19:54 ` [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact() Lee Jones
2026-12-04 20:22 ` Rafael J. Wysocki (Intel)
2026-12-03 19:54 ` [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation Lee Jones
2026-12-04 20:29 ` Rafael J. Wysocki (Intel)
2026-12-03 19:54 ` [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone Lee Jones
2026-12-04 20:24 ` Rafael J. Wysocki (Intel)
2026-12-03 19:54 ` [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration Lee Jones
2026-12-03 19:54 ` [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors Lee Jones
2026-12-03 19:54 ` [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Lee Jones
2026-12-04 17:15 ` Niklas Söderlund [this message]
2026-12-03 19:54 ` [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp() Lee Jones
2026-12-04 10:40 ` Peng Fan (OSS)
2026-12-03 19:54 ` [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating Lee Jones
2026-12-04 20:34 ` Rafael J. Wysocki (Intel)
2026-12-03 19:54 ` [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks Lee Jones
2026-12-03 19:54 ` [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode() Lee Jones
2026-12-03 20:21 ` Frank Li
2026-12-04 10:40 ` Peng Fan (OSS)
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=20261204171528.GA3999746@ragnatech.se \
--to=niklas.soderlund@ragnatech.se \
--cc=daniel.lezcano@kernel.org \
--cc=geert+renesas@glider.be \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lee@kernel.org \
--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 \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox