Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: hisi: handle of_iomap and fix missing of_node_put

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")
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>

authored by

Nicholas Mc Guire and committed by
Wei Xu
d396cb18 81646a3d

+13 -6
+13 -6
arch/arm/mach-hisi/hotplug.c
··· 148 148 struct device_node *node; 149 149 150 150 node = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl"); 151 - if (node) { 152 - ctrl_base = of_iomap(node, 0); 153 - id = HI3620_CTRL; 154 - return 0; 151 + if (!node) { 152 + id = ERROR_CTRL; 153 + return -ENOENT; 155 154 } 156 - id = ERROR_CTRL; 157 - return -ENOENT; 155 + 156 + ctrl_base = of_iomap(node, 0); 157 + of_node_put(node); 158 + if (!ctrl_base) { 159 + id = ERROR_CTRL; 160 + return -ENOMEM; 161 + } 162 + 163 + id = HI3620_CTRL; 164 + return 0; 158 165 } 159 166 160 167 void hi3xxx_set_cpu(int cpu, bool enable)