genirq/irqdomain: Don't try to free an interrupt that has no mapping
Subsystems (2)
PATCH 1/1 genirq/irqdomain: Don't try to free an interrupt that has no mapping
When an interrupt allocation fails for N interrupts, it is pretty common for the error handling code to free the same number of interrupts, no matter how many interrupts have actually been allocated.
This may result in the domain freeing code to be unexpectedly called for interrupts that have no mapping in that domain. Things end pretty badly.
Instead, add some checks to irq_domain_free_irqs_hierarchy() to make sure that we don't follow the hierarchy if no mapping exists for a given interrupt.
--- kernel/irq/irqdomain.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/irq/irqdomain.c +8 -2
@@ -1370,8 +1370,14 @@ static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain,unsigned int irq_base, unsigned int nr_irqs) { - if (domain->ops->free) - domain->ops->free(domain, irq_base, nr_irqs); + int i; + +if (!domain->ops->free) +return ; + +for (i =0 ; i < nr_irqs; i++) +if (irq_domain_get_irq_data (domain, irq_base + i)) + domain->ops->free (domain, irq_base + i,1 ); } int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
Signature · 1 line
2.29.2
Quoted 8 lines · Marc Zyngier
When an interrupt allocation fails for N interrupts, it is pretty common for the error handling code to free the same number of interrupts, no matter how many interrupts have actually been allocated.
This may result in the domain freeing code to be unexpectedly called for interrupts that have no mapping in that domain. Things end pretty badly.
Quoted 5 lines
Instead, add some checks to
irq_domain_free_irqs_hierarchy()to make sure that we don't follow the hierarchy if no mapping exists for a given interrupt.Signed-off-by Marc Zyngier <[email protected]>
A for a good measure:
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 4615fbc3788ddc8e7c6d697714ad35a53729aa2c Gitweb: https://git.kernel.org/tip/4615fbc3788ddc8e7c6d697714ad35a53729aa2c Author: Marc Zyngier <[email protected]> AuthorDate: Sun, 29 Nov 2020 13:55:51 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 30 Nov 2020 14:50:21 +01:00
genirq/irqdomain: Don't try to free an interrupt that has no mapping
When an interrupt allocation fails for N interrupts, it is pretty common for the error handling code to free the same number of interrupts, no matter how many interrupts have actually been allocated.
This may result in the domain freeing code to be unexpectedly called for interrupts that have no mapping in that domain. Things end pretty badly.
Instead, add some checks to irq_domain_free_irqs_hierarchy() to make sure that thiss does not follow the hierarchy if no mapping exists for a given interrupt.
--- kernel/irq/irqdomain.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/irq/irqdomain.c +9 -2
@@ -1381,8 +1381,15 @@ static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain, unsigned int irq_base, unsigned int nr_irqs) { - if (domain->ops->free) - domain->ops->free(domain, irq_base, nr_irqs); +unsigned int i; + +if (!domain->ops->free) +return ; + +for (i =0 ; i < nr_irqs; i++) { +if (irq_domain_get_irq_data (domain, irq_base + i)) + domain->ops->free (domain, irq_base + i,1 ); + } } int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,