[PATCH v2 03/13] iommu/rockchip: Fix error handling in attach

Jeffy Chen
2018-01-16T13:25:30Z

From: Tomasz Figa <tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

Currently if the driver encounters an error while attaching device, it
will leave the IOMMU in an inconsistent state. Even though it shouldn't
really happen in reality, let's just add proper error path to keep
things consistent.

Signed-off-by: Tomasz Figa <tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Signed-off-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---

Changes in v2:
Move irq request to probe(in patch[0])

drivers/iommu/rockchip-iommu.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index da4afe016a4e..4ffb3a65c9d2 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -826,7 +826,7 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,

ret = rk_iommu_force_reset(iommu);
if (ret)
- return ret;
+ goto err_disable_stall;

iommu->domain = domain;

@@ -839,7 +839,7 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,

ret = rk_iommu_enable_paging(iommu);
if (ret)
- return ret;
+ goto err_disable_stall;

spin_lock_irqsave(&rk_domain->iommus_lock, flags);
list_add_tail(&iommu->node, &rk_domain->iommus);
@@ -850,6 +850,11 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
rk_iommu_disable_stall(iommu);

return 0;
+
+err_disable_stall:
+ rk_iommu_disable_stall(iommu);
+
+ return ret;
}

static void rk_iommu_detach_device(struct iommu_domain *domain,
--
2.11.0