Skip to contentSkip to conversation

iommu/rockchip: Clarify of_xlate

PATCH Applied Robin Murphy 2 participants 2 messages Dec 1 – Dec 2

Subsystems (2)
lore
Share & tools
lore

Robin Murphy

author reviewer
#0 lore raw

PATCH v2 1/1 iommu/rockchip: Clarify of_xlate

Technically "leaking" a reference on a platform device which will never be freed anyway, and only under catastrophic OOM conditions, is entirely a non-issue. But the number of attempts to "fix" it with additional pointless checks is getting tiresome (and only made worse by LLMs...), so let's just hoist the refcount drop up to avoid the offending pattern, and add a comment on the general of_xlate flow for clarity.

---

v2: Rebase for devm_kzalloc_obj conversion - turns out one should really pay attention before writing patches on a branch that was left in the middle of a rebase from yesterday...

 drivers/iommu/rockchip-iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/rockchip-iommu.c +6 -2
index 1fa3110b142a..f7dc97e64e52 100644
@@ -1184,7 +1184,13 @@ static int rk_iommu_of_xlate(struct device *dev,
 	struct platform_device *iommu_dev;
 	struct rk_iommudata *data;
 
+	/*
+	 * If we're here at all it's because args->np matched what we passed to
+	 * iommu_device_register(), so iommu_dev is by definition valid and
+	 * referenced already since this driver is currently bound to it!
+	 */
 	iommu_dev = of_find_device_by_node(args->np);
+	platform_device_put(iommu_dev);
 
 	data = devm_kzalloc_obj(&iommu_dev->dev, *data);
 	if (!data)
@@ -1193,8 +1199,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 	data->iommu = platform_get_drvdata(iommu_dev);
 	dev_iommu_priv_set(dev, data);
 
-	platform_device_put(iommu_dev);
-
 	return 0;
 }
 
Signature · 1 line
2.54.0.dirty