From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam01on0126.outbound.protection.outlook.com ([104.47.32.126]:8380 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729484AbeIOGwp (ORCPT ); Sat, 15 Sep 2018 02:52:45 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Nicholas Mc Guire , Wei Xu , Sasha Levin Subject: [PATCH AUTOSEL 3.18 05/11] ARM: hisi: handle of_iomap and fix missing of_node_put Date: Sat, 15 Sep 2018 01:35:27 +0000 Message-ID: <20180915013521.180178-5-alexander.levin@microsoft.com> References: <20180915013521.180178-1-alexander.levin@microsoft.com> In-Reply-To: <20180915013521.180178-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: Nicholas Mc Guire [ Upstream commit d396cb185c0337aae5664b250cdd9a73f6eb1503 ] Relying on an unchecked of_iomap() which can return NULL is problematic here, an explicit check seems mandatory. Also the call to of_find_compatible_node() returns a device node with refcount incremented therefor an explicit of_node_put() is needed here. Signed-off-by: Nicholas Mc Guire Fixes: commit 22bae4290457 ("ARM: hi3xxx: add hotplug support") Signed-off-by: Wei Xu Signed-off-by: Sasha Levin --- arch/arm/mach-hisi/hotplug.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-hisi/hotplug.c b/arch/arm/mach-hisi/hotplug.c index 84e6919f68c7..6385abcd321e 100644 --- a/arch/arm/mach-hisi/hotplug.c +++ b/arch/arm/mach-hisi/hotplug.c @@ -145,13 +145,20 @@ static int hi3xxx_hotplug_init(void) struct device_node *node; =20 node =3D of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl"); - if (node) { - ctrl_base =3D of_iomap(node, 0); - id =3D HI3620_CTRL; - return 0; + if (!node) { + id =3D ERROR_CTRL; + return -ENOENT; } - id =3D ERROR_CTRL; - return -ENOENT; + + ctrl_base =3D of_iomap(node, 0); + of_node_put(node); + if (!ctrl_base) { + id =3D ERROR_CTRL; + return -ENOMEM; + } + + id =3D HI3620_CTRL; + return 0; } =20 void hi3xxx_set_cpu(int cpu, bool enable) --=20 2.17.1