@@ -2523,22 +2523,18 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
25232523 u32 flags , int pgtable )
25242524{
25252525 bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING ;
2526+ struct amd_iommu * iommu = get_amd_iommu_from_dev (dev );
25262527 struct protection_domain * domain ;
2527- struct amd_iommu * iommu = NULL ;
25282528 int ret ;
25292529
2530- if (dev )
2531- iommu = get_amd_iommu_from_dev (dev );
2532-
25332530 /*
25342531 * Since DTE[Mode]=0 is prohibited on SNP-enabled system,
25352532 * default to use IOMMU_DOMAIN_DMA[_FQ].
25362533 */
25372534 if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY ))
25382535 return ERR_PTR (- EINVAL );
25392536
2540- domain = protection_domain_alloc (type ,
2541- dev ? dev_to_node (dev ) : NUMA_NO_NODE );
2537+ domain = protection_domain_alloc (type , dev_to_node (dev ));
25422538 if (!domain )
25432539 return ERR_PTR (- ENOMEM );
25442540
@@ -2554,13 +2550,11 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
25542550 domain -> domain .geometry .force_aperture = true;
25552551 domain -> domain .pgsize_bitmap = domain -> iop .pgtbl .cfg .pgsize_bitmap ;
25562552
2557- if (iommu ) {
2558- domain -> domain .type = type ;
2559- domain -> domain .ops = iommu -> iommu .ops -> default_domain_ops ;
2553+ domain -> domain .type = type ;
2554+ domain -> domain .ops = iommu -> iommu .ops -> default_domain_ops ;
25602555
2561- if (dirty_tracking )
2562- domain -> domain .dirty_ops = & amd_dirty_ops ;
2563- }
2556+ if (dirty_tracking )
2557+ domain -> domain .dirty_ops = & amd_dirty_ops ;
25642558
25652559 return & domain -> domain ;
25662560}
@@ -2571,13 +2565,10 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
25712565
25722566{
25732567 unsigned int type = IOMMU_DOMAIN_UNMANAGED ;
2574- struct amd_iommu * iommu = NULL ;
2568+ struct amd_iommu * iommu = get_amd_iommu_from_dev ( dev ) ;
25752569 const u32 supported_flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
25762570 IOMMU_HWPT_ALLOC_PASID ;
25772571
2578- if (dev )
2579- iommu = get_amd_iommu_from_dev (dev );
2580-
25812572 if ((flags & ~supported_flags ) || user_data )
25822573 return ERR_PTR (- EOPNOTSUPP );
25832574
@@ -2591,10 +2582,9 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
25912582
25922583 /* Allocate domain with v1 page table for dirty tracking */
25932584 if (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING ) {
2594- if (iommu && amd_iommu_hd_support (iommu )) {
2595- return do_iommu_domain_alloc (type , dev ,
2596- flags , AMD_IOMMU_V1 );
2597- }
2585+ if (amd_iommu_hd_support (iommu ))
2586+ return do_iommu_domain_alloc (type , dev , flags ,
2587+ AMD_IOMMU_V1 );
25982588
25992589 return ERR_PTR (- EOPNOTSUPP );
26002590 }
0 commit comments