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

2020-12-29 Thread Yong Wu
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 
> > ---
> >  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(>iommu);
> > if (ret)
> > -   return ret;
> > +   goto out_sysfs_remove;
> >  
> > spin_lock_init(>tlb_lock);
> > list_add_tail(>list, );
> > @@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device 
> > *pdev)
> > if (!iommu_present(_bus_type))
> > bus_set_iommu(_bus_type, _iommu_ops);
> >  
> > -   return component_master_add_with_match(dev, _iommu_com_ops, match);
> > +   ret = component_master_add_with_match(dev, _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(>iommu);
> > +out_sysfs_remove:
> > +   iommu_device_sysfs_remove(>iommu);
> > +   return ret;
> >  }
> >  
> >  static int mtk_iommu_remove(struct platform_device *pdev)
> > -- 
> > 2.18.0
> > 
> > ___
> > iommu mailing list
> > io...@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu



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

2020-12-23 Thread Tomasz Figa
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 
> ---
>  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(>iommu);
>   if (ret)
> - return ret;
> + goto out_sysfs_remove;
>  
>   spin_lock_init(>tlb_lock);
>   list_add_tail(>list, );
> @@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device *pdev)
>   if (!iommu_present(_bus_type))
>   bus_set_iommu(_bus_type, _iommu_ops);
>  
> - return component_master_add_with_match(dev, _iommu_com_ops, match);
> + ret = component_master_add_with_match(dev, _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(>iommu);
> +out_sysfs_remove:
> + iommu_device_sysfs_remove(>iommu);
> + return ret;
>  }
>  
>  static int mtk_iommu_remove(struct platform_device *pdev)
> -- 
> 2.18.0
> 
> ___
> iommu mailing list
> io...@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu


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

2020-12-09 Thread Yong Wu
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 
---
 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(>iommu);
if (ret)
-   return ret;
+   goto out_sysfs_remove;
 
spin_lock_init(>tlb_lock);
list_add_tail(>list, );
@@ -754,7 +754,16 @@ static int mtk_iommu_probe(struct platform_device *pdev)
if (!iommu_present(_bus_type))
bus_set_iommu(_bus_type, _iommu_ops);
 
-   return component_master_add_with_match(dev, _iommu_com_ops, match);
+   ret = component_master_add_with_match(dev, _iommu_com_ops, match);
+   if (ret)
+   goto out_dev_unreg;
+   return ret;
+
+out_dev_unreg:
+   iommu_device_unregister(>iommu);
+out_sysfs_remove:
+   iommu_device_sysfs_remove(>iommu);
+   return ret;
 }
 
 static int mtk_iommu_remove(struct platform_device *pdev)
-- 
2.18.0