Commit 386dce27 authored by Will Deacon's avatar Will Deacon Committed by Joerg Roedel

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: default avatarWill Deacon <will@kernel.org>
Tested-by: John Garry <john.garry@huawei.com> # smmu v3
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 25f003de
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/iommu.h> #include <linux/iommu.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <linux/pci.h> #include <linux/module.h>
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_iommu.h> #include <linux/of_iommu.h>
#include <linux/of_pci.h> #include <linux/of_pci.h>
#include <linux/pci.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/fsl/mc.h> #include <linux/fsl/mc.h>
...@@ -91,16 +92,16 @@ static int of_iommu_xlate(struct device *dev, ...@@ -91,16 +92,16 @@ static int of_iommu_xlate(struct device *dev,
{ {
const struct iommu_ops *ops; const struct iommu_ops *ops;
struct fwnode_handle *fwnode = &iommu_spec->np->fwnode; struct fwnode_handle *fwnode = &iommu_spec->np->fwnode;
int err; int ret;
ops = iommu_ops_from_fwnode(fwnode); ops = iommu_ops_from_fwnode(fwnode);
if ((ops && !ops->of_xlate) || if ((ops && !ops->of_xlate) ||
!of_device_is_available(iommu_spec->np)) !of_device_is_available(iommu_spec->np))
return NO_IOMMU; return NO_IOMMU;
err = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
if (err) if (ret)
return err; return ret;
/* /*
* The otherwise-empty fwspec handily serves to indicate the specific * The otherwise-empty fwspec handily serves to indicate the specific
* IOMMU device we're waiting for, which will be useful if we ever get * IOMMU device we're waiting for, which will be useful if we ever get
...@@ -109,7 +110,12 @@ static int of_iommu_xlate(struct device *dev, ...@@ -109,7 +110,12 @@ static int of_iommu_xlate(struct device *dev,
if (!ops) if (!ops)
return driver_deferred_probe_check_state(dev); 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 { struct of_pci_iommu_alias_info {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment