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>
This commit is contained in:
parent
c71f88426a
commit
c5cc3073f2
1 changed files with 26 additions and 9 deletions
|
@ -756,6 +756,17 @@ static int add_iommu_group(struct device *dev, void *data)
|
||||||
return ops->add_device(dev);
|
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,
|
static int iommu_bus_notifier(struct notifier_block *nb,
|
||||||
unsigned long action, void *data)
|
unsigned long action, void *data)
|
||||||
{
|
{
|
||||||
|
@ -824,19 +835,25 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
|
||||||
nb->notifier_call = iommu_bus_notifier;
|
nb->notifier_call = iommu_bus_notifier;
|
||||||
|
|
||||||
err = bus_register_notifier(bus, nb);
|
err = bus_register_notifier(bus, nb);
|
||||||
if (err) {
|
if (err)
|
||||||
kfree(nb);
|
goto out_free;
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bus_for_each_dev(bus, NULL, &cb, add_iommu_group);
|
err = bus_for_each_dev(bus, NULL, &cb, add_iommu_group);
|
||||||
if (err) {
|
if (err)
|
||||||
bus_unregister_notifier(bus, nb);
|
goto out_err;
|
||||||
kfree(nb);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue