ARM: hisi: fix device_node reference leak in hip04_smp_init
Subsystems (3)
PATCH 1/1 ARM: hisi: fix device_node reference leak in hip04_smp_init
The function hip04_smp_init() uses of_find_compatible_node() to acquire three device_node pointers (np, np_sctl, np_fab), but none of them are released on the success path or on error paths. This results in reference count leaks for the corresponding device tree nodes.
Fix this by:
- Initializing the three pointers to NULL so that of_node_put(NULL) is safe if a node was never acquired but the error path is taken.
- Adding of_node_put() calls for each acquired node on both the success path and the common error path.
Fixes 9cdc99919a95 ("ARM: hisi: enable MCPM implementation")
Signed-off-by Wang Yan <[email protected]>
--- arch/arm/mach-hisi/platmcpm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/mach-hisi/platmcpm.c +7 -1
@@ -264,7 +264,7 @@ static bool __init hip04_cpu_table_init(void)static int __init hip04_smp_init (void ) { -struct device_node *np, *np_sctl, *np_fab; +struct device_node *np =NULL , *np_sctl =NULL , *np_fab =NULL ;struct resource fab_res;void __iomem *relocation;int ret = -ENODEV ;
@@ -331,6 +331,9 @@ static int __init hip04_smp_init(void)iounmap (relocation);smp_set_ops (&hip04_smp_ops); +of_node_put (np_fab); +of_node_put (np_sctl); +of_node_put (np);return ret; err_table:iounmap (fabric);
@@ -341,6 +344,9 @@ static int __init hip04_smp_init(void) err_reloc:memblock_phys_free (hip04_boot_method[0 ], hip04_boot_method[1 ]); err: +of_node_put (np_fab); +of_node_put (np_sctl); +of_node_put (np);return ret; }early_initcall (hip04_smp_init);
Signature · 1 line
2.25.1