irqchip/bcm7038-l1: Fix potential stale handlers on probe failure
Subsystems (4)
PATCH 1/1 irqchip/bcm7038-l1: Fix potential stale handlers on probe failure
IRQ-domain creation can fail after the per-CPU parent handlers have been installed. Freeing the controller without clearing those handlers leaves them referencing freed storage.
Track each installed parent IRQ and detach its handler before releasing the controller. Also unwind partially initialized CPU resources.
This issue was found by our static analysis tool under development.
Fixes 5f7f0317ed28 ("IRQCHIP: Add new driver for BCM7038-style level 1 interrupt controllers")
Signed-off-by Guangshuo Li <[email protected]>
--- drivers/irqchip/irq-bcm7038-l1.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/irqchip/irq-bcm7038-l1.c +10 -2
@@ -48,6 +48,7 @@ struct bcm7038_l1_chip { };struct bcm7038_l1_cpu { +unsigned int parent_irq;void __iomem *map_base;u32 mask_cache[]; };
@@ -267,6 +268,7 @@ static int bcm7038_l1_init_one(struct device_node *dn, unsigned int idx,if (of_property_read_bool (dn,"brcm,irq-can-wake" ))enable_irq_wake (parent_irq); + cpu->parent_irq = parent_irq;irq_set_chained_handler_and_data (parent_irq, bcm7038_l1_irq_handle, intc);
@@ -408,7 +410,7 @@ static int bcm7038_l1_probe(struct platform_device *pdev, struct device_node *paif (idx)break ;pr_err ("failed to remap intc L1 registers\n" ); - goto out_free; + goto out_unmap; } }
@@ -440,12 +442,18 @@ static int bcm7038_l1_probe(struct platform_device *pdev, struct device_node *pastruct bcm7038_l1_cpu *cpu = intc->cpus[idx];if (cpu) { +if (cpu->parent_irq) { +irq_set_chained_handler_and_data (cpu->parent_irq,NULL ,NULL ); +synchronize_irq (cpu->parent_irq); +if (of_property_read_bool (dn,"brcm,irq-can-wake" )) +disable_irq_wake (cpu->parent_irq); +irq_dispose_mapping (cpu->parent_irq); + }if (cpu->map_base)iounmap (cpu->map_base);kfree (cpu); } } -out_free:kfree (intc);return ret; }
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244