[PATCH 6/6] iommu/mediatek: Convert to devm_platform_ioremap_resource() and devm_platform_get_and_ioremap_resource()

Yangtao Li frank.li at vivo.com
Wed Jul 5 06:04:16 PDT 2023


Use devm_platform_ioremap_resource() and
devm_platform_get_and_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <frank.li at vivo.com>
---
 drivers/iommu/mtk_iommu.c    | 9 +++------
 drivers/iommu/mtk_iommu_v1.c | 4 +---
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index e93906d6e112..6595a25c103d 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -1264,16 +1264,13 @@ static int mtk_iommu_probe(struct platform_device *pdev)
 	}
 
 	banks_num = data->plat_data->banks_num;
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EINVAL;
+	base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 	if (resource_size(res) < banks_num * MTK_IOMMU_BANK_SZ) {
 		dev_err(dev, "banknr %d. res %pR is not enough.\n", banks_num, res);
 		return -EINVAL;
 	}
-	base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(base))
-		return PTR_ERR(base);
 	ioaddr = res->start;
 
 	data->bank = devm_kmalloc(dev, banks_num * sizeof(*data->bank), GFP_KERNEL);
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 8a0a5e5d049f..2e116241f80b 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -610,7 +610,6 @@ static int mtk_iommu_v1_probe(struct platform_device *pdev)
 {
 	struct device			*dev = &pdev->dev;
 	struct mtk_iommu_v1_data	*data;
-	struct resource			*res;
 	struct component_match		*match = NULL;
 	void				*protect;
 	int				larb_nr, ret, i;
@@ -628,8 +627,7 @@ static int mtk_iommu_v1_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN);
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	data->base = devm_ioremap_resource(dev, res);
+	data->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
-- 
2.39.0




More information about the Linux-mediatek mailing list