iommu/arm: Constrain return value of ->attach_dev()
Subsystems (4)
PATCH v2 4/13 iommu/arm: Constrain return value of ->attach_dev()
Ensure attach_dev() callback functions only return errno values expected from the attach_dev() op. In particular, only return -EINVAL when we are sure that the device is incompatible with the domain.
Also drop any dev_err next to -EINVAL, following the attach_dev op kdocs.
Signed-off-by Nicolin Chen <[email protected]>
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 ++----------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 7 ++----- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 9 ++------- 3 files changed, 6 insertions(+), 23 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -11
@@ -2402,7 +2402,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)struct arm_smmu_master *master;if (!fwspec) -return -ENOENT ; +return -ENODEV ; master =dev_iommu_priv_get (dev); smmu = master->smmu;
@@ -2429,23 +2429,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) goto out_unlock; } }else if (smmu_domain->smmu != smmu) { -dev_err (dev, -"cannot attach to SMMU %s (upstream of %s)\n" , -dev_name (smmu_domain->smmu->dev), -dev_name (smmu->dev)); - ret = -ENXIO ; + ret = -EINVAL ; goto out_unlock; }else if (smmu_domain->stage ==ARM_SMMU_DOMAIN_S1 && master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) { -dev_err (dev, -"cannot attach to incompatible domain (%u SSID bits != %u)\n" , - smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); ret = -EINVAL ; goto out_unlock; }else if (smmu_domain->stage ==ARM_SMMU_DOMAIN_S1 && smmu_domain->stall_enabled != master->stall_enabled) { -dev_err (dev,"cannot attach to stall-%s domain\n" , - smmu_domain->stall_enabled ?"enabled" :"disabled" ); ret = -EINVAL ; goto out_unlock; }
drivers/iommu/arm/arm-smmu/arm-smmu.c +2 -5
@@ -1137,7 +1137,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)if (!fwspec || fwspec->ops != &arm_smmu_ops) {dev_err (dev,"cannot attach to SMMU, is it on the same bus?\n" ); -return -ENXIO ; +return -ENODEV ; }/*
@@ -1155,7 +1155,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) ret =arm_smmu_rpm_get (smmu);if (ret <0 ) -return ret; +return -ENODEV ;/* Ensure that the domain is finalised */ ret =arm_smmu_init_domain_context (domain, smmu, dev);
@@ -1167,9 +1167,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)* different SMMUs. */ if (smmu_domain->smmu != smmu) { -dev_err (dev, -"cannot attach to SMMU %s whilst already attached to domain on SMMU %s\n" , -dev_name (smmu_domain->smmu->dev),dev_name (smmu->dev)); ret = -EINVAL ; goto rpm_put; }
drivers/iommu/arm/arm-smmu/qcom_iommu.c +2 -7
@@ -367,7 +367,7 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *devif (!qcom_iommu) {dev_err (dev,"cannot attach to IOMMU, is it on the same bus?\n" ); -return -ENXIO ; +return -ENODEV ; }/* Ensure that the domain is finalized */
@@ -381,13 +381,8 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev* Sanity check the domain. We don't support domains across * different IOMMUs. */ -if (qcom_domain->iommu != qcom_iommu) { -dev_err (dev,"cannot attach to IOMMU %s while already " -"attached to domain on IOMMU %s\n" , -dev_name (qcom_domain->iommu->dev), -dev_name (qcom_iommu->dev)); +if (qcom_domain->iommu != qcom_iommu)return -EINVAL ; - }return 0 ; }
Signature · 1 line
2.17.1