[PATCH v4 2/7] iommu/arm-smmu-v3: Factor out a common arm_smmu_domain_alloc()

Jason Gunthorpe jgg at nvidia.com
Sat Jun 1 14:06:55 PDT 2024


On Tue, May 28, 2024 at 08:18:26AM +0100, Shameer Kolothum wrote:

> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -648,7 +648,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain,
>  
>  static void arm_smmu_sva_domain_free(struct iommu_domain *domain)
>  {
> -	kfree(domain);
> +	kfree(to_smmu_domain(domain));
>  }

  
> @@ -659,13 +659,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = {
>  struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev,
>  					       struct mm_struct *mm)
>  {
> -	struct iommu_domain *domain;
> +	struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> +	struct arm_smmu_device *smmu = master->smmu;
> +	struct arm_smmu_domain *smmu_domain;
>  
> -	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> -	if (!domain)
> -		return ERR_PTR(-ENOMEM);
> -	domain->type = IOMMU_DOMAIN_SVA;
> -	domain->ops = &arm_smmu_sva_domain_ops;
> +	smmu_domain = arm_smmu_domain_alloc();
> +	if (IS_ERR(smmu_domain))
> +		return ERR_CAST(smmu_domain);
> +	smmu_domain->domain.type = IOMMU_DOMAIN_SVA;
> +	smmu_domain->domain.ops = &arm_smmu_sva_domain_ops;
> +	smmu_domain->smmu = smmu;
>  
> -	return domain;
> +	return &smmu_domain->domain;
>  }

If you drop these two hunks you can drop the first patch as well. There
is no need to touch SVA in this series

Jason



More information about the linux-arm-kernel mailing list