[PATCH v4 04/14] irqchip/davinci-aintc: Fix potential resource leaks
From: Tiezhu Yang
Date: Tue Jun 30 2020 - 22:16:57 EST
In the function davinci_aintc_init(), system resources "config->reg.start",
"davinci_aintc_base", "irq_base" and "davinci_aintc_irq_domain" were not
released in a few error cases. Thus add jump targets for the completion of
the desired exception handling.
Fixes: 0145beed9d26 ("irqchip: davinci-aintc: move the driver to drivers/irqchip")
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
drivers/irqchip/irq-davinci-aintc.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/irqchip/irq-davinci-aintc.c b/drivers/irqchip/irq-davinci-aintc.c
index 810ccc4..2a96dc9 100644
--- a/drivers/irqchip/irq-davinci-aintc.c
+++ b/drivers/irqchip/irq-davinci-aintc.c
@@ -96,7 +96,7 @@ void __init davinci_aintc_init(const struct davinci_aintc_config *config)
resource_size(&config->reg));
if (!davinci_aintc_base) {
pr_err("%s: unable to ioremap register range\n", __func__);
- return;
+ goto err_release;
}
/* Clear all interrupt requests */
@@ -133,7 +133,7 @@ void __init davinci_aintc_init(const struct davinci_aintc_config *config)
if (irq_base < 0) {
pr_err("%s: unable to allocate interrupt descriptors: %d\n",
__func__, irq_base);
- return;
+ goto err_iounmap;
}
davinci_aintc_irq_domain = irq_domain_add_legacy(NULL,
@@ -141,7 +141,7 @@ void __init davinci_aintc_init(const struct davinci_aintc_config *config)
&irq_domain_simple_ops, NULL);
if (!davinci_aintc_irq_domain) {
pr_err("%s: unable to create interrupt domain\n", __func__);
- return;
+ goto err_free_descs;
}
ret = irq_alloc_domain_generic_chips(davinci_aintc_irq_domain, 32, 1,
@@ -150,7 +150,7 @@ void __init davinci_aintc_init(const struct davinci_aintc_config *config)
if (ret) {
pr_err("%s: unable to allocate generic irq chips for domain\n",
__func__);
- return;
+ goto err_domain_remove;
}
for (irq_off = 0, reg_off = 0;
@@ -160,4 +160,14 @@ void __init davinci_aintc_init(const struct davinci_aintc_config *config)
irq_base + irq_off, 32);
set_handle_irq(davinci_aintc_handle_irq);
+ return;
+
+err_domain_remove:
+ irq_domain_remove(davinci_aintc_irq_domain);
+err_free_descs:
+ irq_free_descs(irq_base, config->num_irqs);
+err_iounmap:
+ iounmap(davinci_aintc_base);
+err_release:
+ release_mem_region(config->reg.start, resource_size(&config->reg));
}
--
2.1.0