[PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove

From: Lee Jones

Date: Thu Dec 03 2026 - 14:56:28 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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;

- 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