From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr690096.outbound.protection.outlook.com ([40.107.69.96]:35711 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727622AbeH3WHD (ORCPT ); Thu, 30 Aug 2018 18:07:03 -0400 From: Sasha Levin To: "stable@vger.kernel.org" CC: Dan Carpenter , Marc Zyngier , Sasha Levin Subject: [PATCH AUTOSEL 4.18 059/113] irqchip/stm32: Fix init error handling Date: Thu, 30 Aug 2018 18:03:33 +0000 Message-ID: <20180830180050.35735-59-alexander.levin@microsoft.com> References: <20180830180050.35735-1-alexander.levin@microsoft.com> In-Reply-To: <20180830180050.35735-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Dan Carpenter [ Upstream commit 4096165d55218a6f58b6c2ebc5d2428aa0aa70e4 ] 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: f9fc1745501e ("irqchip/stm32: Add host and driver data structures") Reviewed-by: Ludovic Barre Signed-off-by: Dan Carpenter Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin --- drivers/irqchip/irq-stm32-exti.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-e= xti.c index 3a7e8905a97e..880e48947576 100644 --- a/drivers/irqchip/irq-stm32-exti.c +++ b/drivers/irqchip/irq-stm32-exti.c @@ -602,17 +602,24 @@ stm32_exti_host_data *stm32_exti_host_init(const stru= ct stm32_exti_drv_data *dd, sizeof(struct stm32_exti_chip_data), GFP_KERNEL); if (!host_data->chips_data) - return NULL; + goto free_host_data; =20 host_data->base =3D of_iomap(node, 0); if (!host_data->base) { pr_err("%pOF: Unable to map registers\n", node); - return NULL; + goto free_chips_data; } =20 stm32_host_data =3D host_data; =20 return host_data; + +free_chips_data: + kfree(host_data->chips_data); +free_host_data: + kfree(host_data); + + return NULL; } =20 static struct @@ -664,10 +671,8 @@ static int __init stm32_exti_init(const struct stm32_e= xti_drv_data *drv_data, struct irq_domain *domain; =20 host_data =3D stm32_exti_host_init(drv_data, node); - if (!host_data) { - ret =3D -ENOMEM; - goto out_free_mem; - } + if (!host_data) + return -ENOMEM; =20 domain =3D irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK, &irq_exti_domain_ops, NULL); @@ -724,7 +729,6 @@ static int __init stm32_exti_init(const struct stm32_ex= ti_drv_data *drv_data, irq_domain_remove(domain); out_unmap: iounmap(host_data->base); -out_free_mem: kfree(host_data->chips_data); kfree(host_data); return ret; @@ -751,10 +755,8 @@ __init stm32_exti_hierarchy_init(const struct stm32_ex= ti_drv_data *drv_data, } =20 host_data =3D stm32_exti_host_init(drv_data, node); - if (!host_data) { - ret =3D -ENOMEM; - goto out_free_mem; - } + if (!host_data) + return -ENOMEM; =20 for (i =3D 0; i < drv_data->bank_nr; i++) stm32_exti_chip_init(host_data, i, node); @@ -776,7 +778,6 @@ __init stm32_exti_hierarchy_init(const struct stm32_ext= i_drv_data *drv_data, =20 out_unmap: iounmap(host_data->base); -out_free_mem: kfree(host_data->chips_data); kfree(host_data); return ret; --=20 2.17.1