Skip to content

Commit

Permalink
iommu: Tidy the control flow in iommu_group_store_type()
Browse files Browse the repository at this point in the history
Use a normal "goto unwind" instead of trying to be clever with checking
!ret and manually managing the unlock.

Reviewed-by: Lu Baolu <[email protected]>
Reviewed-by: Kevin Tian <[email protected]>
Tested-by: Heiko Stuebner <[email protected]>
Tested-by: Niklas Schnelle <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Joerg Roedel <[email protected]>
  • Loading branch information
jgunthorpe authored and joergroedel committed May 23, 2023
1 parent e996c12 commit 5957c19
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions drivers/iommu/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,7 @@ static int iommu_setup_default_domain(struct iommu_group *group,
static ssize_t iommu_group_store_type(struct iommu_group *group,
const char *buf, size_t count)
{
struct group_device *gdev;
int ret, req_type;

if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
Expand All @@ -2964,20 +2965,23 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
if (req_type == IOMMU_DOMAIN_DMA_FQ &&
group->default_domain->type == IOMMU_DOMAIN_DMA) {
ret = iommu_dma_init_fq(group->default_domain);
if (!ret)
group->default_domain->type = IOMMU_DOMAIN_DMA_FQ;
mutex_unlock(&group->mutex);
if (ret)
goto out_unlock;

return ret ?: count;
group->default_domain->type = IOMMU_DOMAIN_DMA_FQ;
ret = count;
goto out_unlock;
}

/* Otherwise, ensure that device exists and no driver is bound. */
if (list_empty(&group->devices) || group->owner_cnt) {
mutex_unlock(&group->mutex);
return -EPERM;
ret = -EPERM;
goto out_unlock;
}

ret = iommu_setup_default_domain(group, req_type);
if (ret)
goto out_unlock;

/*
* Release the mutex here because ops->probe_finalize() call-back of
Expand All @@ -2988,13 +2992,12 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
mutex_unlock(&group->mutex);

/* Make sure dma_ops is appropriatley set */
if (!ret) {
struct group_device *gdev;

for_each_group_device(group, gdev)
iommu_group_do_probe_finalize(gdev->dev);
}
for_each_group_device(group, gdev)
iommu_group_do_probe_finalize(gdev->dev);
return count;

out_unlock:
mutex_unlock(&group->mutex);
return ret ?: count;
}

Expand Down

0 comments on commit 5957c19

Please sign in to comment.