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

soc: amlogic: meson-gx-socinfo: Add of_node_put() before return

The variable np in function meson_gx_socinfo_init takes the return value
of of_find_compatible_node, which gets a node but does not put it. If
this node is not put it may cause a memory leak. Hence put np after its
usefulness has been exhausted.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Fixes: a9daaba2965e ("soc: Add Amlogic SoC Information driver")
Signed-off-by: Kevin Hilman <khilman@baylibre.com>

authored by

Nishka Dasgupta and committed by
Kevin Hilman
49ed86f5 62369971

+3 -1
+3 -1
drivers/soc/amlogic/meson-gx-socinfo.c
··· 141 141 } 142 142 143 143 /* check if chip-id is available */ 144 - if (!of_property_read_bool(np, "amlogic,has-chip-id")) 144 + if (!of_property_read_bool(np, "amlogic,has-chip-id")) { 145 + of_node_put(np); 145 146 return -ENODEV; 147 + } 146 148 147 149 /* node should be a syscon */ 148 150 regmap = syscon_node_to_regmap(np);