All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iommu/rockchip: Fix device reference leak in rk_iommu_of_xlate()
@ 2026-12-02  6:29 ` Xiangwu Lai
  0 siblings, 0 replies; 4+ messages in thread
From: Xiangwu Lai @ 2026-12-02  6:29 UTC (permalink / raw)
  To: joro, will
  Cc: robin.murphy, heiko, iommu, linux-rockchip, linux-kernel,
	Xiangwu Lai

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@cmss.chinamobile.com>
---

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@cmss.chinamobile.com
 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




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02  8:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  6:29 [PATCH v2] iommu/rockchip: Fix device reference leak in rk_iommu_of_xlate() Xiangwu Lai
2026-12-02  6:29 ` Xiangwu Lai
2026-12-02  8:56 ` Jörg Rödel
2026-12-02  8:56   ` Jörg Rödel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.