Skip to content

Commit 2eaa7f8

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd/device: Replace idev->igroup with local variable
With more use of the fields of igroup, use a local vairable instead of using the idev->igroup heavily. No functional change expected. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent bc06f7f commit 2eaa7f8

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,19 @@ static int
333333
iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
334334
struct iommufd_hwpt_paging *hwpt_paging)
335335
{
336+
struct iommufd_group *igroup = idev->igroup;
336337
int rc;
337338

338-
lockdep_assert_held(&idev->igroup->lock);
339+
lockdep_assert_held(&igroup->lock);
339340

340341
rc = iopt_table_enforce_dev_resv_regions(&hwpt_paging->ioas->iopt,
341342
idev->dev,
342-
&idev->igroup->sw_msi_start);
343+
&igroup->sw_msi_start);
343344
if (rc)
344345
return rc;
345346

346-
if (list_empty(&idev->igroup->device_list)) {
347-
rc = iommufd_group_setup_msi(idev->igroup, hwpt_paging);
347+
if (list_empty(&igroup->device_list)) {
348+
rc = iommufd_group_setup_msi(igroup, hwpt_paging);
348349
if (rc) {
349350
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt,
350351
idev->dev);
@@ -484,11 +485,12 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
484485
{
485486
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
486487
bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID;
488+
struct iommufd_group *igroup = idev->igroup;
487489
int rc;
488490

489-
mutex_lock(&idev->igroup->lock);
491+
mutex_lock(&igroup->lock);
490492

491-
if (idev->igroup->hwpt != NULL && idev->igroup->hwpt != hwpt) {
493+
if (igroup->hwpt && igroup->hwpt != hwpt) {
492494
rc = -EINVAL;
493495
goto err_unlock;
494496
}
@@ -506,39 +508,40 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
506508
* reserved regions are only updated during individual device
507509
* attachment.
508510
*/
509-
if (list_empty(&idev->igroup->device_list)) {
511+
if (list_empty(&igroup->device_list)) {
510512
rc = iommufd_hwpt_attach_device(hwpt, idev, pasid);
511513
if (rc)
512514
goto err_unresv;
513-
idev->igroup->hwpt = hwpt;
515+
igroup->hwpt = hwpt;
514516
}
515517
refcount_inc(&hwpt->obj.users);
516-
list_add_tail(&idev->group_item, &idev->igroup->device_list);
517-
mutex_unlock(&idev->igroup->lock);
518+
list_add_tail(&idev->group_item, &igroup->device_list);
519+
mutex_unlock(&igroup->lock);
518520
return 0;
519521
err_unresv:
520522
if (attach_resv)
521523
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
522524
err_unlock:
523-
mutex_unlock(&idev->igroup->lock);
525+
mutex_unlock(&igroup->lock);
524526
return rc;
525527
}
526528

527529
struct iommufd_hw_pagetable *
528530
iommufd_hw_pagetable_detach(struct iommufd_device *idev, ioasid_t pasid)
529531
{
530-
struct iommufd_hw_pagetable *hwpt = idev->igroup->hwpt;
532+
struct iommufd_group *igroup = idev->igroup;
533+
struct iommufd_hw_pagetable *hwpt = igroup->hwpt;
531534
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
532535

533-
mutex_lock(&idev->igroup->lock);
536+
mutex_lock(&igroup->lock);
534537
list_del(&idev->group_item);
535-
if (list_empty(&idev->igroup->device_list)) {
538+
if (list_empty(&igroup->device_list)) {
536539
iommufd_hwpt_detach_device(hwpt, idev, pasid);
537-
idev->igroup->hwpt = NULL;
540+
igroup->hwpt = NULL;
538541
}
539542
if (hwpt_paging && pasid == IOMMU_NO_PASID)
540543
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
541-
mutex_unlock(&idev->igroup->lock);
544+
mutex_unlock(&igroup->lock);
542545

543546
/* Caller must destroy hwpt */
544547
return hwpt;
@@ -610,7 +613,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
610613
unsigned int num_devices;
611614
int rc;
612615

613-
mutex_lock(&idev->igroup->lock);
616+
mutex_lock(&igroup->lock);
614617

615618
if (igroup->hwpt == NULL) {
616619
rc = -EINVAL;
@@ -623,7 +626,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
623626
}
624627

625628
if (hwpt == igroup->hwpt) {
626-
mutex_unlock(&idev->igroup->lock);
629+
mutex_unlock(&igroup->lock);
627630
return NULL;
628631
}
629632

@@ -654,15 +657,15 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
654657
if (num_devices > 1)
655658
WARN_ON(refcount_sub_and_test(num_devices - 1,
656659
&old_hwpt->obj.users));
657-
mutex_unlock(&idev->igroup->lock);
660+
mutex_unlock(&igroup->lock);
658661

659662
/* Caller must destroy old_hwpt */
660663
return old_hwpt;
661664
err_unresv:
662665
if (attach_resv)
663666
iommufd_group_remove_reserved_iova(igroup, hwpt_paging);
664667
err_unlock:
665-
mutex_unlock(&idev->igroup->lock);
668+
mutex_unlock(&igroup->lock);
666669
return ERR_PTR(rc);
667670
}
668671

0 commit comments

Comments
 (0)