Skip to content

Commit 5957c19

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Tidy the control flow in iommu_group_store_type()
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]>
1 parent e996c12 commit 5957c19

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

drivers/iommu/iommu.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,7 @@ static int iommu_setup_default_domain(struct iommu_group *group,
29402940
static ssize_t iommu_group_store_type(struct iommu_group *group,
29412941
const char *buf, size_t count)
29422942
{
2943+
struct group_device *gdev;
29432944
int ret, req_type;
29442945

29452946
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
@@ -2964,20 +2965,23 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
29642965
if (req_type == IOMMU_DOMAIN_DMA_FQ &&
29652966
group->default_domain->type == IOMMU_DOMAIN_DMA) {
29662967
ret = iommu_dma_init_fq(group->default_domain);
2967-
if (!ret)
2968-
group->default_domain->type = IOMMU_DOMAIN_DMA_FQ;
2969-
mutex_unlock(&group->mutex);
2968+
if (ret)
2969+
goto out_unlock;
29702970

2971-
return ret ?: count;
2971+
group->default_domain->type = IOMMU_DOMAIN_DMA_FQ;
2972+
ret = count;
2973+
goto out_unlock;
29722974
}
29732975

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

29802982
ret = iommu_setup_default_domain(group, req_type);
2983+
if (ret)
2984+
goto out_unlock;
29812985

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

29902994
/* Make sure dma_ops is appropriatley set */
2991-
if (!ret) {
2992-
struct group_device *gdev;
2993-
2994-
for_each_group_device(group, gdev)
2995-
iommu_group_do_probe_finalize(gdev->dev);
2996-
}
2995+
for_each_group_device(group, gdev)
2996+
iommu_group_do_probe_finalize(gdev->dev);
2997+
return count;
29972998

2999+
out_unlock:
3000+
mutex_unlock(&group->mutex);
29983001
return ret ?: count;
29993002
}
30003003

0 commit comments

Comments
 (0)