From patchwork Thu Jul 12 09:28:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10521375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1604C6028E for ; Thu, 12 Jul 2018 09:34:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96AE2521E for ; Thu, 12 Jul 2018 09:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDBD8285C4; Thu, 12 Jul 2018 09:34:34 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 719632521E for ; Thu, 12 Jul 2018 09:34:34 +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=o+eK1yrJGKyCnV2aD52BiXHF2Vs7VmyQ5OkGcOaKg3o=; b=njF8SRJ4uKlVTSWtezMMXWzLOU TdOqaHs01ReSqK2OCVOVwlNSGlkYHLkdlwlu7ZxTRbc/RTJxq6xXQnujueMIq2AkzRRy40yDR+tlf AFh9RUcCoGeRiDEXEdc8Jw9cJB5utNI+hn+hwl2e/UCDsAAeySDDQi/AUnbQ8ql1d86ywn8AKwuKX t72FXHTrAXjx53i063qfXxlsseoEyVs/JTRU54VU5lhVPEMgPZ3Dgfo7lW3I12UJpH68gzhtHIh0R S5MmKd4SC5gY6Xt8NRTTJKlPfHFWuoLpECYwndCvtaaL/CeZTqjrcja0q4WtoiAAhNSgZR+EvNmn/ RAIfIKkA==; 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 1fdXza-00064k-CM; Thu, 12 Jul 2018 09:34:30 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdXyu-000536-Kl for linux-arm-kernel@lists.infradead.org; Thu, 12 Jul 2018 09:33:53 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59] (may be forged)) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id w6C9T86M021688; Thu, 12 Jul 2018 11:29:24 +0200 From: Nicholas Mc Guire To: Wei Xu Subject: [PATCH 3/3] ARM: hisi: handle of_iomap and fix missing of_node_put Date: Thu, 12 Jul 2018 11:28:24 +0200 Message-Id: <1531387704-13265-4-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1531387704-13265-1-git-send-email-hofrat@osadl.org> References: <1531387704-13265-1-git-send-email-hofrat@osadl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180712_023349_344382_17768972 X-CRM114-Status: GOOD ( 12.33 ) 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: Wang Long , Nicholas Mc Guire , linux-kernel@vger.kernel.org, Russell King , Haifeng Yan , 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 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") --- Problem found by an experimental coccinelle script The way id is used is a bit redundant with the function return - not really clear if this "double indication" is intentional or just happened ? Also note that hi3xxx_hotplug_init probably should be bool as that is how it is being used - the error return is not actually interpreted beyond detection of failure in its only call site hi3xxx_set_cpu(). 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 | 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 40857bf..4036ffe 100644 --- a/arch/arm/mach-hisi/hotplug.c +++ b/arch/arm/mach-hisi/hotplug.c @@ -148,13 +148,20 @@ static int hi3xxx_hotplug_init(void) struct device_node *node; node = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl"); - if (node) { - ctrl_base = of_iomap(node, 0); - id = HI3620_CTRL; - return 0; + if (!node) { + id = ERROR_CTRL; + return -ENOENT; } - id = ERROR_CTRL; - return -ENOENT; + + ctrl_base = of_iomap(node, 0); + of_node_put(node); + if (!ctrl_base) { + id = ERROR_CTRL; + return -ENOMEM; + } + + id = HI3620_CTRL; + return 0; } void hi3xxx_set_cpu(int cpu, bool enable)