summaryrefslogtreecommitdiff
path: root/drivers/iommu/iommu.c
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2015-05-28 18:41:27 +0200
committerJoerg Roedel <jroedel@suse.de>2015-06-05 15:13:10 +0200
commit8da30142a21e2d7595510892a4c99cf294f7e6f1 (patch)
tree0f1fa73de54a9165c9ae749bb829d3f9cbb302b5 /drivers/iommu/iommu.c
parent19762d7095e6392b6ec56c363a6f29b2119488c2 (diff)
iommu: Clean up after a failed bus initialization
Make sure we call the ->remove_device call-back on all devices already initialized with ->add_device when the bus initialization fails. Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/iommu.c')
-rw-r--r--drivers/iommu/iommu.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9c9336a923cd..f0e0a233c902 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -753,6 +753,17 @@ static int add_iommu_group(struct device *dev, void *data)
return ops->add_device(dev);
}
+static int remove_iommu_group(struct device *dev, void *data)
+{
+ struct iommu_callback_data *cb = data;
+ const struct iommu_ops *ops = cb->ops;
+
+ if (ops->remove_device && dev->iommu_group)
+ ops->remove_device(dev);
+
+ return 0;
+}
+
static int iommu_bus_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
@@ -821,19 +832,25 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
nb->notifier_call = iommu_bus_notifier;
err = bus_register_notifier(bus, nb);
- if (err) {
- kfree(nb);
- return err;
- }
+ if (err)
+ goto out_free;
err = bus_for_each_dev(bus, NULL, &cb, add_iommu_group);
- if (err) {
- bus_unregister_notifier(bus, nb);
- kfree(nb);
- return err;
- }
+ if (err)
+ goto out_err;
+
return 0;
+
+out_err:
+ /* Clean up */
+ bus_for_each_dev(bus, NULL, &cb, remove_iommu_group);
+ bus_unregister_notifier(bus, nb);
+
+out_free:
+ kfree(nb);
+
+ return err;
}
/**