[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250925122756.10910-12-johan@kernel.org>
Date: Thu, 25 Sep 2025 14:27:53 +0200
From: Johan Hovold <johan@...nel.org>
To: Joerg Roedel <joro@...tes.org>,
Will Deacon <will@...nel.org>
Cc: Robin Murphy <robin.murphy@....com>,
Sven Peter <sven@...nel.org>,
Janne Grunau <j@...nau.net>,
Rob Clark <robin.clark@....qualcomm.com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Yong Wu <yong.wu@...iatek.com>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Chen-Yu Tsai <wens@...e.org>,
Thierry Reding <thierry.reding@...il.com>,
Krishna Reddy <vdumpa@...dia.com>,
iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Johan Hovold <johan@...nel.org>,
stable@...r.kernel.org,
Suman Anna <s-anna@...com>
Subject: [PATCH 11/14] iommu/omap: fix device leaks on probe_device()
Make sure to drop the reference taken to the iommu platform devices
during probe_device() on errors and when the device is later released.
Fixes: 9d5018deec86 ("iommu/omap: Add support to program multiple iommus")
Fixes: 7d6827748d54 ("iommu/omap: Fix iommu archdata name for DT-based devices")
Cc: stable@...r.kernel.org # 3.18
Cc: Suman Anna <s-anna@...com>
Signed-off-by: Johan Hovold <johan@...nel.org>
---
drivers/iommu/omap-iommu.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 6fb93927bdb9..77023d49bd24 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1636,7 +1636,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
struct platform_device *pdev;
struct omap_iommu *oiommu;
struct device_node *np;
- int num_iommus, i;
+ int num_iommus, i, ret;
/*
* Allocate the per-device iommu structure for DT-based devices.
@@ -1663,22 +1663,22 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
np = of_parse_phandle(dev->of_node, "iommus", i);
if (!np) {
- kfree(arch_data);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto err_put_iommus;
}
pdev = of_find_device_by_node(np);
if (!pdev) {
of_node_put(np);
- kfree(arch_data);
- return ERR_PTR(-ENODEV);
+ ret = -ENODEV;
+ goto err_put_iommus;
}
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
- kfree(arch_data);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto err_put_iommus;
}
tmp->iommu_dev = oiommu;
@@ -1697,17 +1697,28 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
oiommu = arch_data->iommu_dev;
return &oiommu->iommu;
+
+err_put_iommus:
+ for (tmp = arch_data; tmp->dev; tmp++)
+ put_device(tmp->dev);
+
+ kfree(arch_data);
+
+ return ERR_PTR(ret);
}
static void omap_iommu_release_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev);
+ struct omap_iommu_arch_data *tmp;
if (!dev->of_node || !arch_data)
return;
- kfree(arch_data);
+ for (tmp = arch_data; tmp->dev; tmp++)
+ put_device(tmp->dev);
+ kfree(arch_data);
}
static int omap_iommu_of_xlate(struct device *dev, const struct of_phandle_args *args)
--
2.49.1
Powered by blists - more mailing lists