Skip to content

Commit

Permalink
iommu: Clean up after a failed bus initialization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Joerg Roedel committed Jun 5, 2015
1 parent 19762d7 commit 8da3014
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions drivers/iommu/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 8da3014

Please sign in to comment.