[PATCH v2] iommu/rockchip: Clarify of_xlate

Robin Murphy robin.murphy at arm.com
Tue Dec 1 05:16:03 PST 2026


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.

Signed-off-by: Robin Murphy <robin.murphy at arm.com>
---

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(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 1fa3110b142a..f7dc97e64e52 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -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;
 }
 
-- 
2.54.0.dirty




More information about the Linux-rockchip mailing list