Skip to content

Commit 237603a

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommu: Make @handle mandatory in iommu_{attach|replace}_group_handle()
Caller of the two APIs always provide a valid handle, make @handle as mandatory parameter. Take this chance incoporate the handle->domain set under the protection of group->mutex in iommu_attach_group_handle(). Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Yi Liu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 40f5175 commit 237603a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

drivers/iommu/iommu.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,10 +3511,11 @@ int iommu_attach_group_handle(struct iommu_domain *domain,
35113511
{
35123512
int ret;
35133513

3514-
if (handle)
3515-
handle->domain = domain;
3514+
if (!handle)
3515+
return -EINVAL;
35163516

35173517
mutex_lock(&group->mutex);
3518+
handle->domain = domain;
35183519
ret = xa_insert(&group->pasid_array, IOMMU_NO_PASID, handle, GFP_KERNEL);
35193520
if (ret)
35203521
goto err_unlock;
@@ -3568,16 +3569,14 @@ int iommu_replace_group_handle(struct iommu_group *group,
35683569
void *curr;
35693570
int ret;
35703571

3571-
if (!new_domain)
3572+
if (!new_domain || !handle)
35723573
return -EINVAL;
35733574

35743575
mutex_lock(&group->mutex);
3575-
if (handle) {
3576-
ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL);
3577-
if (ret)
3578-
goto err_unlock;
3579-
handle->domain = new_domain;
3580-
}
3576+
handle->domain = new_domain;
3577+
ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL);
3578+
if (ret)
3579+
goto err_unlock;
35813580

35823581
ret = __iommu_group_set_domain(group, new_domain);
35833582
if (ret)

0 commit comments

Comments
 (0)