[PATCH] powerpc: platforms: 52xx: Fix refcount leak in media5200.c

Liang He windhl at 126.com
Fri Jun 17 00:40:07 AEST 2022


In media5200_init_irq(), of_find_compatible_node() will return a
node pointer with refcount incremented. We should use of_node_put()
in fail path or when it is not used anymore.

Don't worry about 'fpga_np==NULL' as of_node_put() can correctly
handle it.

Signed-off-by: Liang He <windhl at 126.com>
---
 arch/powerpc/platforms/52xx/media5200.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/platforms/52xx/media5200.c b/arch/powerpc/platforms/52xx/media5200.c
index ee367ff3ec8a..33a35fff11b5 100644
--- a/arch/powerpc/platforms/52xx/media5200.c
+++ b/arch/powerpc/platforms/52xx/media5200.c
@@ -174,6 +174,8 @@ static void __init media5200_init_irq(void)
 		goto out;
 	pr_debug("%s: allocated irqhost\n", __func__);
 
+	of_node_put(fpga_np);
+
 	irq_set_handler_data(cascade_virq, &media5200_irq);
 	irq_set_chained_handler(cascade_virq, media5200_irq_cascade);
 
@@ -181,6 +183,7 @@ static void __init media5200_init_irq(void)
 
  out:
 	pr_err("Could not find Media5200 FPGA; PCI interrupts will not work\n");
+	of_node_put(fpga_np);
 }
 
 /*
-- 
2.25.1



More information about the Linuxppc-dev mailing list