[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aN6P_Wt2ruMeKF3w@hovoldconsulting.com>
Date: Thu, 2 Oct 2025 16:45:17 +0200
From: Johan Hovold <johan@...nel.org>
To: Robin Murphy <robin.murphy@....com>
Cc: Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
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, stable@...r.kernel.org,
Suman Anna <s-anna@...com>
Subject: Re: [PATCH 11/14] iommu/omap: fix device leaks on probe_device()
On Thu, Oct 02, 2025 at 01:05:08PM +0100, Robin Murphy wrote:
> On 2025-09-25 1:27 pm, Johan Hovold wrote:
> > @@ -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);
>
> This should just pair with the of_node_put() calls (other than the first
> one, of course), i.e. do it in the success path as well and drop the
> release_device change below. It doesn't serve any purpose for client
> devices to hold additional references on the IOMMU device when those are
> strictly within the lifetime of the IOMMU driver being bound to it anyway.
I kept the reference until release() (even if not strictly needed) as I
mistakenly thought the driver was using the arch data device pointer
directly.
Turns out that one has never been used so I'll drop it as well as part
of v2.
Johan
Powered by blists - more mailing lists