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

ARM: hisi: check of_iomap and fix missing of_node_put

of_find_compatible_node() returns a device node with refcount incremented
and thus needs an explicit of_node_put(). Further relying on an unchecked
of_iomap() which can return NULL is problematic here, after all ctrl_base
is critical enough for hix5hd2_set_cpu() to call BUG() if not available
so a check seems mandated here.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
0002 Fixes: commit 06cc5c1d4d73 ("ARM: hisi: enable hix5hd2 SoC")
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>

authored by

Nicholas Mc Guire and committed by
Wei Xu
81646a3d 9f30b5ae

+9 -5
+9 -5
arch/arm/mach-hisi/hotplug.c
··· 173 173 struct device_node *np; 174 174 175 175 np = of_find_compatible_node(NULL, NULL, "hisilicon,cpuctrl"); 176 - if (np) { 177 - ctrl_base = of_iomap(np, 0); 178 - return true; 179 - } 180 - return false; 176 + if (!np) 177 + return false; 178 + 179 + ctrl_base = of_iomap(np, 0); 180 + of_node_put(np); 181 + if (!ctrl_base) 182 + return false; 183 + 184 + return true; 181 185 } 182 186 183 187 void hix5hd2_set_cpu(int cpu, bool enable)