drivers/iommu/omap-iommu.c | 1 + 1 file changed, 1 insertion(+)
The reference taken by 'of_find_device_by_node()' must be released when
not needed anymore.
Add the corresponding 'put_device()' in the error handling paths.
Fixes: ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/iommu/omap-iommu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 91749654fd49..cbc7ca5e890a 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1684,6 +1684,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
+ put_device(&pdev->dev);
kfree(arch_data);
return ERR_PTR(-EINVAL);
}
--
2.17.1
Hi Miaoqian,
On 1/7/22 2:04 AM, Miaoqian Lin wrote:
> The reference taken by 'of_find_device_by_node()' must be released when
> not needed anymore.
Thanks for catching this.
> Add the corresponding 'put_device()' in the error handling paths.
Also, need it in the regular path, not just in error handling path.
>
> Fixes: ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/iommu/omap-iommu.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
> index 91749654fd49..cbc7ca5e890a 100644
> --- a/drivers/iommu/omap-iommu.c
> +++ b/drivers/iommu/omap-iommu.c
> @@ -1684,6 +1684,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
> oiommu = platform_get_drvdata(pdev);
> if (!oiommu) {
> of_node_put(np);
> + put_device(&pdev->dev);
nit, doesn't matter for functionality, but prefer the put_device before
of_node_put().
regards
Suman
> kfree(arch_data);
> return ERR_PTR(-EINVAL);
> }
>
Hi Suman Anna, On Fri, Jan 07, 2022 at 08:42:16AM -0600, Suman Anna wrote: > Hi Miaoqian, > > > > Add the corresponding 'put_device()' in the error handling paths. > > Also, need it in the regular path, not just in error handling path. I think after calling platform_get_drvdata() normally, the reference will be released in other functions, so don't need it in the regular path.
Hi Miaoqian, On 1/9/22 8:43 PM, Miaoqian Lin wrote: > Hi Suman Anna, > On Fri, Jan 07, 2022 at 08:42:16AM -0600, Suman Anna wrote: >> Hi Miaoqian, >> >> >>> Add the corresponding 'put_device()' in the error handling paths. >> >> Also, need it in the regular path, not just in error handling path. > I think after calling platform_get_drvdata() normally, the > reference will be released in other functions, so don't need it in the > regular path. > No, it's a local reference and is acquired within omap_iommu_probe_device() and needs to be released within this function. What other function are you referring to here? regards Suman
Hi Suman, On Mon, Jan 10, 2022 at 12:43:57PM -0600, Suman Anna wrote: > Hi Miaoqian, > > On 1/9/22 8:43 PM, Miaoqian Lin wrote: > > Hi Suman Anna, > > On Fri, Jan 07, 2022 at 08:42:16AM -0600, Suman Anna wrote: > >> Hi Miaoqian, > >> > >> > >>> Add the corresponding 'put_device()' in the error handling paths. > >> > >> Also, need it in the regular path, not just in error handling path. > > I think after calling platform_get_drvdata() normally, the > > reference will be released in other functions, so don't need it in the > > regular path. > > > > No, it's a local reference and is acquired within omap_iommu_probe_device() and > needs to be released within this function. What other function are you referring > to here? > I am referring to the release function of this device, here is omap_iommu_release_device(). But I find omap_iommu_release_device() doesn't handle the reference, and calls kfree(arch_data) directly.
The reference taken by 'of_find_device_by_node()' must be released when
not needed anymore.
Add the corresponding 'put_device()' in the error handling path and
the regular path.
Fixes: ede1c2e7d4dc ("iommu/omap: Store iommu_dev pointer in arch_data")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- move put_device() before of_node_put().
- add put_device() in the regular path.
---
drivers/iommu/omap-iommu.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 91749654fd49..2222b30a0a00 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1683,6 +1683,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
+ put_device(&pdev->dev);
of_node_put(np);
kfree(arch_data);
return ERR_PTR(-EINVAL);
@@ -1691,6 +1692,7 @@ static struct iommu_device *omap_iommu_probe_device(struct device *dev)
tmp->iommu_dev = oiommu;
tmp->dev = &pdev->dev;
+ put_device(&pdev->dev);
of_node_put(np);
}
--
2.17.1
© 2016 - 2026 Red Hat, Inc.