[PATCH v4] irqchip/renesas-irqc: fix generic interrupt chip leak on remove
Qingshuang Fu <[email protected]>
| Newsgroups | org.kernel.vger.linux-renesas-soc,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Qingshuang Fu <[email protected]> The driver allocates domain generic chips using irq_alloc_domain_generic_chips() during probe. However, on driver remove, the generic chips are not automatically freed when the interrupt domain is removed because the domain flags do not include IRQ_DOMAIN_FLAG_DESTROY_GC. This causes both the domain generic chips structure and the associated generic chips to be leaked. Additionally, the generic chips remain on the global gc_list and may later be visited by generic interrupt chip suspend, resume, or shutdown callbacks after the driver has been removed, potentially resulting in a use-after-free and kernel crash. Fix the resource leak by setting IRQ_DOMAIN_FLAG_DESTROY_GC on the interrupt domain; this lets the interrupt domain core automatically release all generic chips when irq_domain_remove() is called, removing the need for manual cleanup calls in error paths and remove callback. Fixes: 99c221df33fbfa1b ("irqchip/renesas-irqc: Move over to nested generic chip") Signed-off-by: Qingshuang Fu <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> --- drivers/irqchip/irq-renesas-irqc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c index a20a6471b0e4..4b8b86c89b6a 100644 --- a/drivers/irqchip/irq-renesas-irqc.c +++ b/drivers/irqchip/irq-renesas-irqc.c @@ -194,6 +194,9 @@ static int irqc_probe(struct platform_device *pdev) p->gc->chip_types[0].chip.irq_set_wake = irqc_irq_set_wake; p->gc->chip_types[0].chip.flags = IRQCHIP_MASK_ON_SUSPEND; + /* Automatically free generic chips when interrupt domain is destroyed */ + p->irq_domain->flags |= IRQ_DOMAIN_FLAG_DESTROY_GC; + irq_domain_set_pm_device(p->irq_domain, dev); /* request interrupts one by one */ base-commit: 0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53 -- 2.25.1