From: Nicholas Mc Guire <hofrat@osadl.org>
To: Wei Xu <xuwei5@hisilicon.com>
Cc: Wang Long <long.wanglong@huawei.com>,
Haifeng Yan <yanhaifeng@gmail.com>,
Russell King <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH 3/3] ARM: hisi: handle of_iomap and fix missing of_node_put
Date: Thu, 12 Jul 2018 11:28:24 +0200 [thread overview]
Message-ID: <1531387704-13265-4-git-send-email-hofrat@osadl.org> (raw)
In-Reply-To: <1531387704-13265-1-git-send-email-hofrat@osadl.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 <hofrat@osadl.org>
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
next prev parent reply other threads:[~2018-07-12 9:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-12 9:28 [PATCH 0/3] ARM: hisi: fix of_iomap errors Nicholas Mc Guire
2018-07-12 9:28 ` [PATCH 1/3] ARM: hisi: fix error handling and missing of_node_put Nicholas Mc Guire
2018-07-12 9:28 ` [PATCH 2/3] ARM: hisi: check of_iomap and fix " Nicholas Mc Guire
2018-07-12 9:28 ` Nicholas Mc Guire [this message]
2018-07-18 15:36 ` [PATCH 0/3] ARM: hisi: fix of_iomap errors Wei Xu
2019-04-13 7:14 [PATCH 0/4] ARM: imx legacy: cleanups Nicholas Mc Guire
2019-04-13 7:14 ` [PATCH 3/3] ARM: hisi: handle of_iomap and fix missing of_node_put Nicholas Mc Guire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1531387704-13265-4-git-send-email-hofrat@osadl.org \
--to=hofrat@osadl.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=long.wanglong@huawei.com \
--cc=xuwei5@hisilicon.com \
--cc=yanhaifeng@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®