Skip to content
Snippets Groups Projects
Commit b9abb19f authored by Shameer Kolothum's avatar Shameer Kolothum Committed by Joerg Roedel
Browse files

iommu: Check dev->iommu in iommu_dev_xxx functions


The device iommu probe/attach might have failed leaving dev->iommu
to NULL and device drivers may still invoke these functions resulting
in a crash in iommu vendor driver code.

Hence make sure we check that.

Fixes: a3a19592 ("iommu: Add APIs for multiple domains per device")
Signed-off-by: default avatarShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: default avatarRobin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20210303173611.520-1-shameerali.kolothum.thodi@huawei.com


Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 1e28eed1
No related branches found
No related tags found
No related merge requests found
...@@ -2878,10 +2878,12 @@ EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); ...@@ -2878,10 +2878,12 @@ EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids);
*/ */
int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat) int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat)
{ {
const struct iommu_ops *ops = dev->bus->iommu_ops; if (dev->iommu && dev->iommu->iommu_dev) {
const struct iommu_ops *ops = dev->iommu->iommu_dev->ops;
if (ops && ops->dev_enable_feat) if (ops->dev_enable_feat)
return ops->dev_enable_feat(dev, feat); return ops->dev_enable_feat(dev, feat);
}
return -ENODEV; return -ENODEV;
} }
...@@ -2894,10 +2896,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_enable_feature); ...@@ -2894,10 +2896,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_enable_feature);
*/ */
int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat) int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat)
{ {
const struct iommu_ops *ops = dev->bus->iommu_ops; if (dev->iommu && dev->iommu->iommu_dev) {
const struct iommu_ops *ops = dev->iommu->iommu_dev->ops;
if (ops && ops->dev_disable_feat) if (ops->dev_disable_feat)
return ops->dev_disable_feat(dev, feat); return ops->dev_disable_feat(dev, feat);
}
return -EBUSY; return -EBUSY;
} }
...@@ -2905,10 +2909,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_disable_feature); ...@@ -2905,10 +2909,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_disable_feature);
bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat)
{ {
const struct iommu_ops *ops = dev->bus->iommu_ops; if (dev->iommu && dev->iommu->iommu_dev) {
const struct iommu_ops *ops = dev->iommu->iommu_dev->ops;
if (ops && ops->dev_feat_enabled) if (ops->dev_feat_enabled)
return ops->dev_feat_enabled(dev, feat); return ops->dev_feat_enabled(dev, feat);
}
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment