[PATCH] powerpc/cell: Hold reference returned by of_find_node_by_xxx APIs

Liang He windhl at 126.com
Tue Jun 21 17:53:33 AEST 2022


In cell_iommu_init_disabled() and cbe_get_be_node(), we need to
hold the reference returned by of_find_node_by_xxx APIs and use
it to call of_node_put() for refcount balance.

Signed-off-by: Liang He <windhl at 126.com>
---
 arch/powerpc/platforms/cell/cbe_regs.c | 10 ++++++++--
 arch/powerpc/platforms/cell/iommu.c    |  5 ++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/cell/cbe_regs.c b/arch/powerpc/platforms/cell/cbe_regs.c
index 316e533afc00..09cbdfc070b3 100644
--- a/arch/powerpc/platforms/cell/cbe_regs.c
+++ b/arch/powerpc/platforms/cell/cbe_regs.c
@@ -182,9 +182,15 @@ static struct device_node *__init cbe_get_be_node(int cpu_id)
 		if (WARN_ON_ONCE(!cpu_handle))
 			return np;
 
-		for (i=0; i<len; i++)
-			if (of_find_node_by_phandle(cpu_handle[i]) == of_get_cpu_node(cpu_id, NULL))
+		for (i=0; i<len; i++) {
+			struct device_node *ch_np = of_find_node_by_phandle(cpu_handle[i]);
+			struct device_node *ci_np = of_get_cpu_node(cpu_id, NULL);
+
+			of_node_put(ch_np);
+			of_node_put(ci_np);
+			if (ch_np == ci_np)
 				return np;
+		}
 	}
 
 	return NULL;
diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
index 0ca3efeef293..3ba3742c4ae7 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -719,8 +719,11 @@ static int __init cell_iommu_init_disabled(void)
 	/* First make sure all IOC translation is turned off */
 	cell_disable_iommus();
 
+	np = of_find_node_by_name(NULL, "axon")
+	of_node_put(np);
+
 	/* If we have no Axon, we set up the spider DMA magic offset */
-	if (of_find_node_by_name(NULL, "axon") == NULL)
+	if (!np)
 		cell_dma_nommu_offset = SPIDER_DMA_OFFSET;
 
 	/* Now we need to check to see where the memory is mapped
-- 
2.25.1



More information about the Linuxppc-dev mailing list