diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-10-06 01:14:25 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-10-06 01:14:25 +0200 |
commit | 4f2a541e99b381c39b822ddaffb8f3941217463a (patch) | |
tree | c6ca944114ff625805a0b62835e55adb84f8d436 | |
parent | ba4b80512c3c8e777db6b536f281e0bc74c054ad (diff) |
delete devices before recreating them
-rw-r--r-- | device.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -228,6 +228,16 @@ struct device *device_get(const char *name, bool create) return dev; } +static void +device_delete(struct device *dev) +{ + if (!dev->avl.key) + return; + + avl_delete(&devices, &dev->avl); + dev->avl.key = NULL; +} + void device_cleanup(struct device *dev) { struct device_user *dep, *tmp; @@ -240,8 +250,7 @@ void device_cleanup(struct device *dev) dep->cb(dep, DEV_EVENT_REMOVE); } - if (dev->avl.key) - avl_delete(&devices, &dev->avl); + device_delete(dev); } void device_set_present(struct device *dev, bool state) @@ -392,6 +401,7 @@ device_create(const char *name, const struct device_type *type, return odev; case DEV_CONFIG_RECREATE: D(DEVICE, "Device '%s': recreate device\n", odev->ifname); + device_delete(odev); break; } } |