Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1478029imm; Thu, 12 Jul 2018 02:34:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcuCxSjXBPwv4YSr0nJgdZHGdgqsBwNNKuoO7B0h0s5HeccRTqHOIP6uytr/b6sWD9oG1YA X-Received: by 2002:a62:c0a:: with SMTP id u10-v6mr1567726pfi.43.1531388091332; Thu, 12 Jul 2018 02:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531388091; cv=none; d=google.com; s=arc-20160816; b=j08lPDo0rcJA7Lk/qANz12jxGtHl6hUFv5MNRTYT+mVP0fvOv1UrT9iVCMvJ3c/jee YnOnM0GTAqhN9paJ3mduvwMRBDb46jDYaERJDVUoQsAXGmzmajPfQCyj9blMQpHYI6MU x89u8+TLBBe2YEbFkrLJ+f/Dg5mjfgKDyelJ8QRWoLnuj8ng5QdrQtXE4q/DRF2kOAhB JK3fG1xrhwxpU73Far7b4edQ1HQqsCoM/xF1pHs3RvOoYADZvYpE+W51wgRPWKyU5Ouj oOb7aHDIfprYOdnu5Q3whjYqQNN94bqM0Lvcfonvhnd+KlybVSKtS1b9UBgoSZSY+j42 wRRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=rKeVxS1YhnV/5XPt28s+MtXFZd9OyzJRZDRwUEOb8Xw=; b=lrXoXAy6/DaJJjSdmdkb6YVc27J9hL1vMxiWBFIqCZjTo6ZtvoTSvWP6OdnRbtPwno +F7trDaI3A8YIit58jBLRvAbQBn0mKskdKZc+NP0q8TmCjVdp+vhN4VKe+8n05ahY/s9 mCqN/YrMbthKVLXtokZqrTSGhJsJI7kLkT4cRBQTzu/m4EPsmhtneikrCXdY1RfGuKGe s/MIvdIhi0w8ywgJLTgd0hoFvI/+4zzSuiMFySHlxVB2yM3ZZJCi8nIpmQXH22BIJKHa yw/rnSHowOLoreXLdf0LgErlK1hCcnqhHSAkJrgLwYOFVRIHl9GAl9crrwcixEr7Ruk+ GKMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v129-v6si23202587pfc.330.2018.07.12.02.34.35; Thu, 12 Jul 2018 02:34:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbeGLJml (ORCPT + 99 others); Thu, 12 Jul 2018 05:42:41 -0400 Received: from www.osadl.org ([62.245.132.105]:51758 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeGLJmk (ORCPT ); Thu, 12 Jul 2018 05:42:40 -0400 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 Cc: Wang Long , Haifeng Yan , Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire 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-Spam-Status: No, score=0.4 required=6.0 tests=BAYES_00,DATE_IN_FUTURE_96_Q autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.1.4