Skip to content

Commit a186120

Browse files
Dan CarpenterKAGA-KOKO
authored andcommitted
irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc()
Code in gicv5_its_irq_domain_alloc() has two issues: - it checks the wrong return value/variable when calling gicv5_alloc_lpi() - The cleanup code does not take previous loop iterations into account Fix both issues at once by adding the right gicv5_alloc_lpi() variable check and by reworking the function cleanup code to take into account current and previous iterations. [ lpieralisi: Reworded commit message ] Fixes: 57d7219 ("irqchip/gic-v5: Add GICv5 ITS support") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Zenghui Yu <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent bfcd1fd commit a186120

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/irqchip/irq-gic-v5-its.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,15 +947,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
947947
device_id = its_dev->device_id;
948948

949949
for (i = 0; i < nr_irqs; i++) {
950-
lpi = gicv5_alloc_lpi();
950+
ret = gicv5_alloc_lpi();
951951
if (ret < 0) {
952952
pr_debug("Failed to find free LPI!\n");
953-
goto out_eventid;
953+
goto out_free_irqs;
954954
}
955+
lpi = ret;
955956

956957
ret = irq_domain_alloc_irqs_parent(domain, virq + i, 1, &lpi);
957-
if (ret)
958-
goto out_free_lpi;
958+
if (ret) {
959+
gicv5_free_lpi(lpi);
960+
goto out_free_irqs;
961+
}
959962

960963
/*
961964
* Store eventid and deviceid into the hwirq for later use.
@@ -975,8 +978,13 @@ static int gicv5_its_irq_domain_alloc(struct irq_domain *domain, unsigned int vi
975978

976979
return 0;
977980

978-
out_free_lpi:
979-
gicv5_free_lpi(lpi);
981+
out_free_irqs:
982+
while (--i >= 0) {
983+
irqd = irq_domain_get_irq_data(domain, virq + i);
984+
gicv5_free_lpi(irqd->parent_data->hwirq);
985+
irq_domain_reset_irq_data(irqd);
986+
irq_domain_free_irqs_parent(domain, virq + i, 1);
987+
}
980988
out_eventid:
981989
gicv5_its_free_eventid(its_dev, event_id_base, nr_irqs);
982990
return ret;

0 commit comments

Comments
 (0)