[PATCH v2] iommu/rockchip: Fix device reference leak in rk_iommu_of_xlate()

From: Xiangwu Lai

Date: Wed Dec 02 2026 - 01:29:32 EST


rk_iommu_of_xlate() takes a reference on the IOMMU platform device
with of_find_device_by_node(), but when the subsequent per-device
data allocation fails the reference is only dropped on the success
path, so the error path leaks it on every client device whose DT
translation hits the allocation failure. The platform device is
also dereferenced without a NULL check.

Check the platform device and release the reference on the
allocation failure path.

Fixes: f48dcda8f6a4 ("iommu/rockchip: Allocate per-device data sensibly")
Signed-off-by: Xiangwu Lai <laixiangwu@xxxxxxxxxxxxxxxxxxxx>
---

Changes in v2:
- Rebased onto v7.4-rc4 as requested by Joerg: the treewide conversion
to the devm_kzalloc_obj() family rewrote the devm_kzalloc() call that
the v1 hunk used as context. No change to the fix itself, the diffstat
is identical.

Link: https://lore.kernel.org/r/20261112021845.1867-1-laixiangwu@xxxxxxxxxxxxxxxxxxxx
drivers/iommu/rockchip-iommu.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 1fa3110..72a5243 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1185,10 +1185,14 @@ static int rk_iommu_of_xlate(struct device *dev,
struct rk_iommudata *data;

iommu_dev = of_find_device_by_node(args->np);
+ if (!iommu_dev)
+ return -ENODEV;

data = devm_kzalloc_obj(&iommu_dev->dev, *data);
- if (!data)
+ if (!data) {
+ platform_device_put(iommu_dev);
return -ENOMEM;
+ }

data->iommu = platform_get_drvdata(iommu_dev);
dev_iommu_priv_set(dev, data);
--
2.50.1.windows.1