From caa640e869a8e2244e69f9d02e4dc13a7d567cc8 Mon Sep 17 00:00:00 2001 From: Ding Wei Date: Wed, 29 Apr 2020 20:42:01 +0800 Subject: [PATCH] video: rockchip: mpp: add rollback when iommu probe error when error, it must realse the got resource. Change-Id: Ib1c8f4495c41c0a82dda2ab087c6dd7a04c3e7ab Signed-off-by: Ding Wei --- drivers/video/rockchip/mpp/mpp_iommu.c | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/video/rockchip/mpp/mpp_iommu.c b/drivers/video/rockchip/mpp/mpp_iommu.c index c00c1247c65c..3354549da83e 100644 --- a/drivers/video/rockchip/mpp/mpp_iommu.c +++ b/drivers/video/rockchip/mpp/mpp_iommu.c @@ -369,33 +369,27 @@ mpp_iommu_probe(struct device *dev) #ifdef CONFIG_ARM_DMA_USE_IOMMU struct dma_iommu_mapping *mapping; #endif + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); np = of_parse_phandle(dev->of_node, "iommus", 0); if (!np || !of_device_is_available(np)) { mpp_err("failed to get device node\n"); - ret = -ENODEV; - goto err; - } - pdev = of_find_device_by_node(np); - if (!pdev) { - mpp_err("failed to get platform device\n"); - ret = -ENODEV; - goto err; + return ERR_PTR(-ENODEV); } - info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) { - ret = -ENOMEM; - goto err; + pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pdev) { + mpp_err("failed to get platform device\n"); + return ERR_PTR(-ENODEV); } - info->dev = dev; - info->pdev = pdev; - init_rwsem(&info->rw_sem); info->group = iommu_group_get(dev); if (!info->group) { ret = -EINVAL; - goto err_free_info; + goto err_put_pdev; } /* @@ -418,13 +412,17 @@ mpp_iommu_probe(struct device *dev) } } + info->dev = dev; + info->pdev = pdev; + init_rwsem(&info->rw_sem); + return info; err_put_group: iommu_group_put(info->group); -err_free_info: - kfree(info); -err: +err_put_pdev: + platform_device_put(pdev); + return ERR_PTR(ret); } @@ -437,7 +435,7 @@ int mpp_iommu_remove(struct mpp_iommu_info *info) arm_iommu_release_mapping(mapping); #endif iommu_group_put(info->group); - kfree(info); + platform_device_put(info->pdev); return 0; }