Skip to content

Commit 386dce2

Browse files
willdeaconjoergroedel
authored andcommitted
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 <will@kernel.org> Tested-by: John Garry <john.garry@huawei.com> # smmu v3 Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 25f003d commit 386dce2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/iommu/of_iommu.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#include <linux/export.h>
99
#include <linux/iommu.h>
1010
#include <linux/limits.h>
11-
#include <linux/pci.h>
11+
#include <linux/module.h>
1212
#include <linux/msi.h>
1313
#include <linux/of.h>
1414
#include <linux/of_iommu.h>
1515
#include <linux/of_pci.h>
16+
#include <linux/pci.h>
1617
#include <linux/slab.h>
1718
#include <linux/fsl/mc.h>
1819

@@ -91,16 +92,16 @@ static int of_iommu_xlate(struct device *dev,
9192
{
9293
const struct iommu_ops *ops;
9394
struct fwnode_handle *fwnode = &iommu_spec->np->fwnode;
94-
int err;
95+
int ret;
9596

9697
ops = iommu_ops_from_fwnode(fwnode);
9798
if ((ops && !ops->of_xlate) ||
9899
!of_device_is_available(iommu_spec->np))
99100
return NO_IOMMU;
100101

101-
err = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
102-
if (err)
103-
return err;
102+
ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
103+
if (ret)
104+
return ret;
104105
/*
105106
* The otherwise-empty fwspec handily serves to indicate the specific
106107
* 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,
109110
if (!ops)
110111
return driver_deferred_probe_check_state(dev);
111112

112-
return ops->of_xlate(dev, iommu_spec);
113+
if (!try_module_get(ops->owner))
114+
return -ENODEV;
115+
116+
ret = ops->of_xlate(dev, iommu_spec);
117+
module_put(ops->owner);
118+
return ret;
113119
}
114120

115121
struct of_pci_iommu_alias_info {

0 commit comments

Comments
 (0)