Skip to contentSkip to conversation

powerpc/cell: Hold reference returned by of_find_node_by_xxx APIs

PATCH New Liang He 1 participant 1 message Jun 21, 2022

Subsystems (2)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 powerpc/cell: Hold reference returned by of_find_node_by_xxx APIs

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.

---
 arch/powerpc/platforms/cell/cbe_regs.c | 10 ++++++++--
 arch/powerpc/platforms/cell/iommu.c    |  5 ++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
arch/powerpc/platforms/cell/cbe_regs.c +8 -2
index 316e533afc00..09cbdfc070b3 100644
@@ -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;
arch/powerpc/platforms/cell/iommu.c +4 -1
index 0ca3efeef293..3ba3742c4ae7 100644
@@ -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
Signature · 1 line
2.25.1