From 012da77b609c9e29befa8e8ed911fb83b72e934b Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Fri, 8 Nov 2019 13:24:17 +0000 Subject: [PATCH] FROMLIST: iommu/of: Take a ref to the IOMMU driver during ->of_xlate() Ensure that we hold a reference to the IOMMU driver module while calling the '->of_xlate()' callback during early device probing. Signed-off-by: Will Deacon Bug: 140290589 Link: https://lore.kernel.org/lkml/20191121114918.2293-6-will@kernel.org/ Signed-off-by: Will Deacon Change-Id: Ica9ef2d5ed172c2451c0a19538dc28852c2270d5 --- drivers/iommu/of_iommu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 78faa9f73a91..25491403a0bd 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -89,16 +90,16 @@ static int of_iommu_xlate(struct device *dev, { const struct iommu_ops *ops; struct fwnode_handle *fwnode = &iommu_spec->np->fwnode; - int err; + int ret; ops = iommu_ops_from_fwnode(fwnode); if ((ops && !ops->of_xlate) || !of_device_is_available(iommu_spec->np)) return NO_IOMMU; - err = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); - if (err) - return err; + ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); + if (ret) + return ret; /* * The otherwise-empty fwspec handily serves to indicate the specific * IOMMU device we're waiting for, which will be useful if we ever get @@ -107,7 +108,12 @@ static int of_iommu_xlate(struct device *dev, if (!ops) return driver_deferred_probe_check_state(dev); - return ops->of_xlate(dev, iommu_spec); + if (!try_module_get(ops->owner)) + return -ENODEV; + + ret = ops->of_xlate(dev, iommu_spec); + module_put(ops->owner); + return ret; } struct of_pci_iommu_alias_info {