Skip to content

Commit 4096165

Browse files
Dan CarpenterMarc Zyngier
authored andcommitted
irqchip/stm32: Fix init error handling
If there are any errors in stm32_exti_host_init() then it leads to a NULL dereference in the callers. The function should clean up after itself. Fixes: f9fc174 ("irqchip/stm32: Add host and driver data structures") Reviewed-by: Ludovic Barre <ludovic.barre@st.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 0702bc4 commit 4096165

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/irqchip/irq-stm32-exti.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,24 @@ stm32_exti_host_data *stm32_exti_host_init(const struct stm32_exti_drv_data *dd,
602602
sizeof(struct stm32_exti_chip_data),
603603
GFP_KERNEL);
604604
if (!host_data->chips_data)
605-
return NULL;
605+
goto free_host_data;
606606

607607
host_data->base = of_iomap(node, 0);
608608
if (!host_data->base) {
609609
pr_err("%pOF: Unable to map registers\n", node);
610-
return NULL;
610+
goto free_chips_data;
611611
}
612612

613613
stm32_host_data = host_data;
614614

615615
return host_data;
616+
617+
free_chips_data:
618+
kfree(host_data->chips_data);
619+
free_host_data:
620+
kfree(host_data);
621+
622+
return NULL;
616623
}
617624

618625
static struct
@@ -664,10 +671,8 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data,
664671
struct irq_domain *domain;
665672

666673
host_data = stm32_exti_host_init(drv_data, node);
667-
if (!host_data) {
668-
ret = -ENOMEM;
669-
goto out_free_mem;
670-
}
674+
if (!host_data)
675+
return -ENOMEM;
671676

672677
domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK,
673678
&irq_exti_domain_ops, NULL);
@@ -724,7 +729,6 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data,
724729
irq_domain_remove(domain);
725730
out_unmap:
726731
iounmap(host_data->base);
727-
out_free_mem:
728732
kfree(host_data->chips_data);
729733
kfree(host_data);
730734
return ret;
@@ -751,10 +755,8 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
751755
}
752756

753757
host_data = stm32_exti_host_init(drv_data, node);
754-
if (!host_data) {
755-
ret = -ENOMEM;
756-
goto out_free_mem;
757-
}
758+
if (!host_data)
759+
return -ENOMEM;
758760

759761
for (i = 0; i < drv_data->bank_nr; i++)
760762
stm32_exti_chip_init(host_data, i, node);
@@ -776,7 +778,6 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
776778

777779
out_unmap:
778780
iounmap(host_data->base);
779-
out_free_mem:
780781
kfree(host_data->chips_data);
781782
kfree(host_data);
782783
return ret;

0 commit comments

Comments
 (0)