Skip to content

Commit 5b4ea8b

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/of: Use -ENODEV consistently in of_iommu_configure()
Instead of returning 1 and trying to handle positive error codes just stick to the convention of returning -ENODEV. Remove references to ops from of_iommu_configure(), a NULL ops will already generate an error code. There is no reason to check dev->bus, if err=0 at this point then the called configure functions thought there was an iommu and we should try to probe it. Remove it. Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: Moritz Fischer <moritzf@google.com> Tested-by: Hector Martin <marcan@marcan.st> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/3-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 6ff6e18 commit 5b4ea8b

1 file changed

Lines changed: 15 additions & 34 deletions

File tree

drivers/iommu/of_iommu.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <linux/slab.h>
1818
#include <linux/fsl/mc.h>
1919

20-
#define NO_IOMMU 1
21-
2220
static int of_iommu_xlate(struct device *dev,
2321
struct of_phandle_args *iommu_spec)
2422
{
@@ -29,7 +27,7 @@ static int of_iommu_xlate(struct device *dev,
2927
ops = iommu_ops_from_fwnode(fwnode);
3028
if ((ops && !ops->of_xlate) ||
3129
!of_device_is_available(iommu_spec->np))
32-
return NO_IOMMU;
30+
return -ENODEV;
3331

3432
ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
3533
if (ret)
@@ -61,7 +59,7 @@ static int of_iommu_configure_dev_id(struct device_node *master_np,
6159
"iommu-map-mask", &iommu_spec.np,
6260
iommu_spec.args);
6361
if (err)
64-
return err == -ENODEV ? NO_IOMMU : err;
62+
return err;
6563

6664
err = of_iommu_xlate(dev, &iommu_spec);
6765
of_node_put(iommu_spec.np);
@@ -72,7 +70,7 @@ static int of_iommu_configure_dev(struct device_node *master_np,
7270
struct device *dev)
7371
{
7472
struct of_phandle_args iommu_spec;
75-
int err = NO_IOMMU, idx = 0;
73+
int err = -ENODEV, idx = 0;
7674

7775
while (!of_parse_phandle_with_args(master_np, "iommus",
7876
"#iommu-cells",
@@ -117,9 +115,8 @@ static int of_iommu_configure_device(struct device_node *master_np,
117115
int of_iommu_configure(struct device *dev, struct device_node *master_np,
118116
const u32 *id)
119117
{
120-
const struct iommu_ops *ops = NULL;
121118
struct iommu_fwspec *fwspec;
122-
int err = NO_IOMMU;
119+
int err;
123120

124121
if (!master_np)
125122
return -ENODEV;
@@ -153,37 +150,21 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
153150
} else {
154151
err = of_iommu_configure_device(master_np, dev, id);
155152
}
156-
157-
/*
158-
* Two success conditions can be represented by non-negative err here:
159-
* >0 : there is no IOMMU, or one was unavailable for non-fatal reasons
160-
* 0 : we found an IOMMU, and dev->fwspec is initialised appropriately
161-
* <0 : any actual error
162-
*/
163-
if (!err) {
164-
/* The fwspec pointer changed, read it again */
165-
fwspec = dev_iommu_fwspec_get(dev);
166-
ops = fwspec->ops;
167-
}
168153
mutex_unlock(&iommu_probe_device_lock);
169154

170-
/*
171-
* If we have reason to believe the IOMMU driver missed the initial
172-
* probe for dev, replay it to get things in order.
173-
*/
174-
if (!err && dev->bus)
175-
err = iommu_probe_device(dev);
176-
177-
/* Ignore all other errors apart from EPROBE_DEFER */
178-
if (err < 0) {
179-
if (err == -EPROBE_DEFER)
180-
return err;
181-
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
155+
if (err == -ENODEV || err == -EPROBE_DEFER)
182156
return err;
183-
}
184-
if (!ops)
185-
return -ENODEV;
157+
if (err)
158+
goto err_log;
159+
160+
err = iommu_probe_device(dev);
161+
if (err)
162+
goto err_log;
186163
return 0;
164+
165+
err_log:
166+
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
167+
return err;
187168
}
188169

189170
static enum iommu_resv_type __maybe_unused

0 commit comments

Comments
 (0)