Re: [PATCH 7/8] iommu: Clean up open-coded ownership checks

From: Jason Gunthorpe
Date: Thu Jan 19 2023 - 14:31:25 EST


On Thu, Jan 19, 2023 at 07:18:25PM +0000, Robin Murphy wrote:
> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> index 270c3d9128ba..b2d3d309be1e 100644
> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> @@ -79,16 +79,6 @@ static struct qcom_iommu_domain *to_qcom_iommu_domain(struct iommu_domain *dom)
>
> static const struct iommu_ops qcom_iommu_ops;
>
> -static struct qcom_iommu_dev * to_iommu(struct device *dev)
> -{
> - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> -
> - if (!fwspec || fwspec->ops != &qcom_iommu_ops)
> - return NULL;
> -
> - return dev_iommu_priv_get(dev);
> -}
> -
> static struct qcom_iommu_ctx * to_ctx(struct qcom_iommu_domain *d, unsigned asid)
> {
> struct qcom_iommu_dev *qcom_iommu = d->iommu;
> @@ -361,7 +351,7 @@ static void qcom_iommu_domain_free(struct iommu_domain *domain)
>
> static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
> {
> - struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
> + struct qcom_iommu_dev *qcom_iommu = dev_iommu_priv_get(dev);
> struct qcom_iommu_domain *qcom_domain = to_qcom_iommu_domain(domain);
> int ret;

The confusing checks for null qcom_iommu following this should go away
too, right?

It should not be possible to have an ops set on the device but have an
invalid priv..

Jason