Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp279898yba; Sat, 13 Apr 2019 00:23:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxThgP6dK7+i21UF1T9M3DPZDD7+56WVFzNACt9c4bqI7rvz/Gzt95NZbn6gXuPcNmJLky9 X-Received: by 2002:a63:5953:: with SMTP id j19mr55154949pgm.260.1555140225067; Sat, 13 Apr 2019 00:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555140225; cv=none; d=google.com; s=arc-20160816; b=cUHq7PPVWnQw4yDpvyM1x8PqztI0xga2zGefWX+FvpWOOkrjut0vvywveRZSvr7Su3 Vdo8YeQKHHASx0ZNlmsn0dZkPqrnvUbjPfkLlR2Hn5aSrIsZ2RNXFn9zUTiYR13AdFr0 Vkv5H2aj8xILmvzvRVL3CylMuHjJJiqea1xHn/vyJAss0YSpKAaG6VFvbkQ5t1EMmb3M uRgqi0R4d55dlxhpdLBRhgfUCc66vNOJTOocP7MAkK+bTEgnGkoLzORF+N+QSTag+qGa o30tuWeI3MBW9SXdKkoUyFcHIBSKP1+ptL5Vnf/HAhzJOwjot4HiQnwsMcnhGcTSm7kh p1cQ== 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; bh=rKeVxS1YhnV/5XPt28s+MtXFZd9OyzJRZDRwUEOb8Xw=; b=IbNi/v3tu6zyHzRDFxSlYpvuCQkvQqiM8LJ5HaxbtZ3AlMkYfQ/2rlcjenz/YWfhFG Wo3usYUoZgF/3KTJCfT9m07eoOTctFhgwUoJtUrHo/dCfUK5wIwt6W21Ua1LhFVFCA8c 2q+3SK8ZHJ+Pm7cK/oaufghM7N+NQItIUf9q1ggJjYY8XyMKZM9GPPEomxJtXUKKwk6+ lEtUJdMuUlw7OgsuBEk1MQABq2b6l/VZYQtutllaohP6Ozdhzv2YHZTBHFkrrknBAdM9 9vb40UDzpL72Lgq9tnx4yrcd+cmyml0wqrvMAGN0jdFbUjDxSCqjBaI+Enj8LD+nqNm2 b31w== 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 j143si39288714pfd.124.2019.04.13.00.23.29; Sat, 13 Apr 2019 00:23:45 -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 S1727317AbfDMHVl (ORCPT + 99 others); Sat, 13 Apr 2019 03:21:41 -0400 Received: from www.osadl.org ([62.245.132.105]:36446 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbfDMHVl (ORCPT ); Sat, 13 Apr 2019 03:21:41 -0400 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 x3D7JfAa003435; Sat, 13 Apr 2019 09:20:45 +0200 From: Nicholas Mc Guire To: Russell King Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Mark Brown , Linus Walleij , Tony Lindgren , Mike Rapoport , Janusz Krzysztofik , 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: Sat, 13 Apr 2019 09:14:24 +0200 Message-Id: <1555139666-948-13-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-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00,DATE_IN_FUTURE_96_Q, RCVD_IN_DNSWL_MED autolearn=ham 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