[PATCH] iommu/ipmmu-vmsa: Avoid leak OF node on error

2022-05-23 Thread cgel . zte
From: Minghao Chi 

The OF node should be put before returning error in ipmmu_init(),
otherwise node's refcount will be leaked.

Reported-by: Zeal Robot 
Signed-off-by: Minghao Chi 
---
 drivers/iommu/ipmmu-vmsa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 8fdb84b3642b..f6440b106f46 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -1179,11 +1179,10 @@ static int __init ipmmu_init(void)
return 0;
 
np = of_find_matching_node(NULL, ipmmu_of_ids);
+   of_node_put(np);
if (!np)
return 0;
 
-   of_node_put(np);
-
ret = platform_driver_register(_driver);
if (ret < 0)
return ret;
-- 
2.25.1


___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH] iommu/omap: using pm_runtime_resume_and_get to simplify the code

2022-04-19 Thread cgel . zte
From: Minghao Chi 

Using pm_runtime_resume_and_get() to replace pm_runtime_get_sync and
pm_runtime_put_noidle. This change is just to simplify the code, no
actual functional changes.

Reported-by: Zeal Robot 
Signed-off-by: Minghao Chi 
---
 drivers/iommu/omap-iommu.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 4aab631ef517..7cfa80ccd9a8 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -193,9 +193,7 @@ static int iommu_enable(struct omap_iommu *obj)
 {
int ret;
 
-   ret = pm_runtime_get_sync(obj->dev);
-   if (ret < 0)
-   pm_runtime_put_noidle(obj->dev);
+   ret = pm_runtime_resume_and_get(obj->dev);
 
return ret < 0 ? ret : 0;
 }
-- 
2.25.1


___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH] iommu: add null pointer check

2022-03-28 Thread cgel . zte
From: Lv Ruyi 

kmem_cache_zalloc is a memory allocation function which can return NULL
when some internal memory errors happen. Add null pointer check to avoid
dereferencing null pointer.

Reported-by: Zeal Robot 
Signed-off-by: Lv Ruyi 
---
 drivers/iommu/fsl_pamu_domain.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 69a4a62dc3b9..43849c027298 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -152,6 +152,10 @@ static void attach_device(struct fsl_dma_domain 
*dma_domain, int liodn, struct d
}
 
info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_ATOMIC);
+   if (!info) {
+   spin_unlock_irqrestore(_domain_lock, flags);
+   return;
+   }
 
info->dev = dev;
info->liodn = liodn;
-- 
2.25.1

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH] drivers/iommu: use struct_size over open coded arithmetic

2022-02-16 Thread cgel . zte
From: Minghao Chi (CGEL ZTE) 

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kzalloc(). For example:

struct viommu_request {
...
unsigned intlen;
charbuf[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot 
Signed-off-by: Minghao Chi (CGEL ZTE) 
---
 drivers/iommu/virtio-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index f2aa34f57454..0996d9c7c358 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -231,7 +231,7 @@ static int __viommu_add_req(struct viommu_dev *viommu, void 
*buf, size_t len,
if (write_offset <= 0)
return -EINVAL;
 
-   req = kzalloc(sizeof(*req) + len, GFP_ATOMIC);
+   req = kzalloc(struct_size(req, buf, len), GFP_ATOMIC);
if (!req)
return -ENOMEM;
 
-- 
2.25.1

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu