Return-Path: Received: from mail-by2nam03on0095.outbound.protection.outlook.com ([104.47.42.95]:43489 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754570AbeCHE4C (ORCPT ); Wed, 7 Mar 2018 23:56:02 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Corey Minyard , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 01/78] ipmi_si: Fix error handling of platform device Date: Thu, 8 Mar 2018 04:56:00 +0000 Message-ID: <20180308045525.7662-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: Corey Minyard [ Upstream commit 174134ac760275457bb0d1560a0dbe6cf8a12ad6 ] Cleanup of platform devices created by the IPMI driver was not being done correctly and could result in a memory leak. So create a local boolean to know how to clean up those platform devices. Reported-by: David Binderman Signed-off-by: Corey Minyard Signed-off-by: Sasha Levin --- drivers/char/ipmi/ipmi_si_intf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_i= ntf.c index 71fad747c0c7..7499b0cd8326 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -2045,6 +2045,7 @@ static int try_smi_init(struct smi_info *new_smi) int rv =3D 0; int i; char *init_name =3D NULL; + bool platform_device_registered =3D false; =20 pr_info(PFX "Trying %s-specified %s state machine at %s address 0x%lx, sl= ave address 0x%x, irq %d\n", ipmi_addr_src_to_str(new_smi->io.addr_source), @@ -2173,6 +2174,7 @@ static int try_smi_init(struct smi_info *new_smi) rv); goto out_err; } + platform_device_registered =3D true; } =20 dev_set_drvdata(new_smi->io.dev, new_smi); @@ -2279,10 +2281,11 @@ static int try_smi_init(struct smi_info *new_smi) } =20 if (new_smi->pdev) { - platform_device_unregister(new_smi->pdev); + if (platform_device_registered) + platform_device_unregister(new_smi->pdev); + else + platform_device_put(new_smi->pdev); new_smi->pdev =3D NULL; - } else if (new_smi->pdev) { - platform_device_put(new_smi->pdev); } =20 kfree(init_name); --=20 2.14.1