From: Felix Fietkau Date: Wed, 5 Oct 2011 23:14:25 +0000 (+0200) Subject: delete devices before recreating them X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4f2a541e99b381c39b822ddaffb8f3941217463a;p=oweals%2Fnetifd.git delete devices before recreating them --- diff --git a/device.c b/device.c index b40f661..42b78e3 100644 --- a/device.c +++ b/device.c @@ -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; } }