summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-06 01:14:25 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-06 01:14:25 +0200
commit4f2a541e99b381c39b822ddaffb8f3941217463a (patch)
treec6ca944114ff625805a0b62835e55adb84f8d436
parentba4b80512c3c8e777db6b536f281e0bc74c054ad (diff)
delete devices before recreating them
-rw-r--r--device.c14
1 files changed, 12 insertions, 2 deletions
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;
}
}