2020-12-09 14:00:04

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v5 15/27] iommu/mediatek: Add fail handle for sysfs_add and device_register

Add fail handle for iommu_device_sysfs_add and iommu_device_register.

Fixes: b16c0170b53c ("iommu/mediatek: Make use of iommu_device_register interface")
Signed-off-by: Yong Wu <[email protected]>
---
drivers/iommu/mtk_iommu.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 39478cfbe0f1..09c8c58feb78 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -746,7 +746,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)

ret = iommu_device_register(&data->iommu);
if (ret)
- return ret;
+ goto out_sysfs_remove;

spin_lock_init(&data->tlb_lock);
list_add_tail(&data->list, &m4ulist);
@@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device *pdev)
if (!iommu_present(&platform_bus_type))
bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);

- return component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
+ ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
+ if (ret)
+ goto out_dev_unreg;
+ return ret;
+
+out_dev_unreg:
+ iommu_device_unregister(&data->iommu);
+out_sysfs_remove:
+ iommu_device_sysfs_remove(&data->iommu);
+ return ret;
}

static int mtk_iommu_remove(struct platform_device *pdev)
--
2.18.0


2020-12-23 08:27:45

by Tomasz Figa

[permalink] [raw]
Subject: Re: [PATCH v5 15/27] iommu/mediatek: Add fail handle for sysfs_add and device_register

On Wed, Dec 09, 2020 at 04:00:50PM +0800, Yong Wu wrote:
> Add fail handle for iommu_device_sysfs_add and iommu_device_register.
>
> Fixes: b16c0170b53c ("iommu/mediatek: Make use of iommu_device_register interface")
> Signed-off-by: Yong Wu <[email protected]>
> ---
> drivers/iommu/mtk_iommu.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> index 39478cfbe0f1..09c8c58feb78 100644
> --- a/drivers/iommu/mtk_iommu.c
> +++ b/drivers/iommu/mtk_iommu.c
> @@ -746,7 +746,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
>
> ret = iommu_device_register(&data->iommu);
> if (ret)
> - return ret;
> + goto out_sysfs_remove;
>
> spin_lock_init(&data->tlb_lock);
> list_add_tail(&data->list, &m4ulist);
> @@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device *pdev)
> if (!iommu_present(&platform_bus_type))
> bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);
>
> - return component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
> + ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
> + if (ret)
> + goto out_dev_unreg;
> + return ret;
> +
> +out_dev_unreg:

Shouldn't other operations be undone as well? I can see that above
bus_set_iommu() is set and an entry is added to m4ulist.

> + iommu_device_unregister(&data->iommu);
> +out_sysfs_remove:
> + iommu_device_sysfs_remove(&data->iommu);
> + return ret;
> }
>
> static int mtk_iommu_remove(struct platform_device *pdev)
> --
> 2.18.0
>
> _______________________________________________
> iommu mailing list
> [email protected]
> https://lists.linuxfoundation.org/mailman/listinfo/iommu

2020-12-29 11:04:08

by Yong Wu (吴勇)

[permalink] [raw]
Subject: Re: [PATCH v5 15/27] iommu/mediatek: Add fail handle for sysfs_add and device_register

On Wed, 2020-12-23 at 17:25 +0900, Tomasz Figa wrote:
> On Wed, Dec 09, 2020 at 04:00:50PM +0800, Yong Wu wrote:
> > Add fail handle for iommu_device_sysfs_add and iommu_device_register.
> >
> > Fixes: b16c0170b53c ("iommu/mediatek: Make use of iommu_device_register interface")
> > Signed-off-by: Yong Wu <[email protected]>
> > ---
> > drivers/iommu/mtk_iommu.c | 13 +++++++++++--
> > 1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 39478cfbe0f1..09c8c58feb78 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -746,7 +746,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
> >
> > ret = iommu_device_register(&data->iommu);
> > if (ret)
> > - return ret;
> > + goto out_sysfs_remove;
> >
> > spin_lock_init(&data->tlb_lock);
> > list_add_tail(&data->list, &m4ulist);
> > @@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device *pdev)
> > if (!iommu_present(&platform_bus_type))
> > bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);
> >
> > - return component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
> > + ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
> > + if (ret)
> > + goto out_dev_unreg;
> > + return ret;
> > +
> > +out_dev_unreg:
>
> Shouldn't other operations be undone as well? I can see that above
> bus_set_iommu() is set and an entry is added to m4ulist.

Oh. Yes. I will add them. and remove the fixes tag since they are not
introduced by it. these error handle are not added in the first version.

>
> > + iommu_device_unregister(&data->iommu);
> > +out_sysfs_remove:
> > + iommu_device_sysfs_remove(&data->iommu);
> > + return ret;
> > }
> >
> > static int mtk_iommu_remove(struct platform_device *pdev)
> > --
> > 2.18.0
> >
> > _______________________________________________
> > iommu mailing list
> > [email protected]
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu