9
0
Fork 0

devices: unregister children when unregistering a device

We currently do not allow to unregister a device when it
has children. However, the return value is seldomly checked.
Also this breaks for hot pluggable devices like USB which we have
to unregister when they disappear. The best way to fix this is to
unregister our children and also the partitions on the unregistered
device.
We unregister the device first and then afterwards the children.
We do this because for example network devices have a miidev as
child which they unregister themselves. So we only have to
unregister the children which are not cleaned up by the drivers,
namely fs devices.
Also, unregister all partitions on a disappearing device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-02-13 19:46:10 +01:00
parent 62d8b2f8c0
commit 491cc29b0a
1 changed files with 15 additions and 5 deletions

View File

@ -137,16 +137,26 @@ EXPORT_SYMBOL(register_device);
int unregister_device(struct device_d *old_dev)
{
debug("unregister_device: %s\n", dev_name(old_dev));
struct cdev *cdev, *ct;
struct device_d *child, *dt;
if (!list_empty(&old_dev->children)) {
errno = -EBUSY;
return errno;
}
dev_dbg(old_dev, "unregister\n");
if (old_dev->driver)
old_dev->bus->remove(old_dev);
list_for_each_entry_safe(child, dt, &old_dev->children, sibling) {
dev_dbg(old_dev, "unregister child %s\n", dev_name(child));
unregister_device(child);
}
list_for_each_entry_safe(cdev, ct, &old_dev->cdevs, devices_list) {
if (cdev->flags & DEVFS_IS_PARTITION) {
dev_dbg(old_dev, "unregister part %s\n", cdev->name);
devfs_del_partition(cdev->name);
}
}
list_del(&old_dev->list);
list_del(&old_dev->active);