From patchwork Sat Apr 13 07:14:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10899343 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AF5917E1 for ; Sat, 13 Apr 2019 07:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 720E428E89 for ; Sat, 13 Apr 2019 07:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6536228E91; Sat, 13 Apr 2019 07:23:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 091D628E89 for ; Sat, 13 Apr 2019 07:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2xZ3tIXhxjb1qvX7b31U6ip8oFxLUUZvRqg0yaXgBtk=; b=Ogvode/ve00TXwWJ94VTcVSslW SBYvLzwX6hmYlLyzOQGYx/w60BbXQbHzB6ZTO4XxE5yeRAdHa+adTq8K11hD7/PLTmbOVRZesOpb2 TOw77hYZlFiiWn7dN8N5fQ13tR9KmSnsl+ZbeRahjFOTSeA/X40U82n9mAm25EHQe++hOD3dCXliW apk4GW6tA4tTHgszFbjVfiIzXUUBkwWXYPae6abD8CKspjQiBMeHyKnXIBh0UxM9A0V5TaaJGfA8o 3sIhnY91HklDLS6O0lR2irZ6YPOaj5eoU3kdDsHyAvw5tRtjpAuU9fNb174tGH5liRRxoikB8GODx TqlSfV9g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hFD0Z-0006R2-EY; Sat, 13 Apr 2019 07:23:27 +0000 Received: from www.osadl.org ([2001:a60:9266:ffff:62:245:132:105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hFCz0-0004ik-L2 for linux-arm-kernel@lists.infradead.org; Sat, 13 Apr 2019 07:21:54 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id x3D7JfAY003435; Sat, 13 Apr 2019 09:20:34 +0200 From: Nicholas Mc Guire To: Russell King Subject: [PATCH 2/3] ARM: hisi: check of_iomap and fix missing of_node_put Date: Sat, 13 Apr 2019 09:14:22 +0200 Message-Id: <1555139666-948-11-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1555139666-948-1-git-send-email-hofrat@osadl.org> References: <1555139666-948-1-git-send-email-hofrat@osadl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190413_002151_354709_7BAD774E X-CRM114-Status: GOOD ( 10.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Rapoport , Tony Lindgren , Shawn Guo , Sascha Hauer , Janusz Krzysztofik , linux-kernel@vger.kernel.org, Mark Brown , NXP Linux Team , Pengutronix Kernel Team , Nicholas Mc Guire , Fabio Estevam , Linus Walleij , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP of_find_compatible_node() returns a device node with refcount incremented and thus needs an explicit of_node_put(). Further relying on an unchecked of_iomap() which can return NULL is problematic here, after all ctrl_base is critical enough for hix5hd2_set_cpu() to call BUG() if not available so a check seems mandated here. Signed-off-by: Nicholas Mc Guire 0002 Fixes: commit 06cc5c1d4d73 ("ARM: hisi: enable hix5hd2 SoC") --- Problem found by an experimental coccinelle script Patch was compile tested with: hisi_defconfig (implies CONFIG_SMP=y) Patch is against 4.18-rc3 (localversion-next is next-20180712) arch/arm/mach-hisi/hotplug.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-hisi/hotplug.c b/arch/arm/mach-hisi/hotplug.c index 3b0d1c6..40857bf 100644 --- a/arch/arm/mach-hisi/hotplug.c +++ b/arch/arm/mach-hisi/hotplug.c @@ -173,11 +173,15 @@ static bool hix5hd2_hotplug_init(void) struct device_node *np; np = of_find_compatible_node(NULL, NULL, "hisilicon,cpuctrl"); - if (np) { - ctrl_base = of_iomap(np, 0); - return true; - } - return false; + if (!np) + return false; + + ctrl_base = of_iomap(np, 0); + of_node_put(np); + if (!ctrl_base) + return false; + + return true; } void hix5hd2_set_cpu(int cpu, bool enable)