@@ -996,39 +996,49 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
996
996
return rc ;
997
997
}
998
998
999
- /* Replace the mock domain with a manually allocated hw_pagetable */
1000
- static int iommufd_test_mock_domain_replace (struct iommufd_ucmd * ucmd ,
1001
- unsigned int device_id , u32 pt_id ,
1002
- struct iommu_test_cmd * cmd )
999
+ static struct selftest_obj *
1000
+ iommufd_test_get_selftest_obj (struct iommufd_ctx * ictx , u32 id )
1003
1001
{
1004
1002
struct iommufd_object * dev_obj ;
1005
1003
struct selftest_obj * sobj ;
1006
- int rc ;
1007
1004
1008
1005
/*
1009
1006
* Prefer to use the OBJ_SELFTEST because the destroy_rwsem will ensure
1010
1007
* it doesn't race with detach, which is not allowed.
1011
1008
*/
1012
- dev_obj =
1013
- iommufd_get_object (ucmd -> ictx , device_id , IOMMUFD_OBJ_SELFTEST );
1009
+ dev_obj = iommufd_get_object (ictx , id , IOMMUFD_OBJ_SELFTEST );
1014
1010
if (IS_ERR (dev_obj ))
1015
- return PTR_ERR (dev_obj );
1011
+ return ERR_CAST (dev_obj );
1016
1012
1017
1013
sobj = to_selftest_obj (dev_obj );
1018
1014
if (sobj -> type != TYPE_IDEV ) {
1019
- rc = - EINVAL ;
1020
- goto out_dev_obj ;
1015
+ iommufd_put_object ( ictx , dev_obj ) ;
1016
+ return ERR_PTR ( - EINVAL ) ;
1021
1017
}
1018
+ return sobj ;
1019
+ }
1020
+
1021
+ /* Replace the mock domain with a manually allocated hw_pagetable */
1022
+ static int iommufd_test_mock_domain_replace (struct iommufd_ucmd * ucmd ,
1023
+ unsigned int device_id , u32 pt_id ,
1024
+ struct iommu_test_cmd * cmd )
1025
+ {
1026
+ struct selftest_obj * sobj ;
1027
+ int rc ;
1028
+
1029
+ sobj = iommufd_test_get_selftest_obj (ucmd -> ictx , device_id );
1030
+ if (IS_ERR (sobj ))
1031
+ return PTR_ERR (sobj );
1022
1032
1023
1033
rc = iommufd_device_replace (sobj -> idev .idev , IOMMU_NO_PASID , & pt_id );
1024
1034
if (rc )
1025
- goto out_dev_obj ;
1035
+ goto out_sobj ;
1026
1036
1027
1037
cmd -> mock_domain_replace .pt_id = pt_id ;
1028
1038
rc = iommufd_ucmd_respond (ucmd , sizeof (* cmd ));
1029
1039
1030
- out_dev_obj :
1031
- iommufd_put_object (ucmd -> ictx , dev_obj );
1040
+ out_sobj :
1041
+ iommufd_put_object (ucmd -> ictx , & sobj -> obj );
1032
1042
return rc ;
1033
1043
}
1034
1044
0 commit comments