X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=device.c;h=ef706853e7806771cff66274a35433457f0e7ab7;hp=6b409a02fa167f69a2947a1e60c6bc5784500158;hb=20adacee2080e29cad3571da073d7fb4909230b1;hpb=fe105ac00422a8ea2250e921e76b801a3d23aa8c diff --git a/device.c b/device.c index 6b409a0..ef70685 100644 --- a/device.c +++ b/device.c @@ -3,24 +3,17 @@ #include #include -#include - #include "netifd.h" #include "system.h" static struct avl_tree devices; -static int avl_strcmp(const void *k1, const void *k2, void *ptr) -{ - return strcmp(k1, k2); -} - -static void API_CTOR dev_init(void) +static void __init dev_init(void) { avl_init(&devices, avl_strcmp, false, NULL); } -static void free_device(struct device *dev) +static void free_simple_device(struct device *dev) { cleanup_device(dev); free(dev); @@ -126,7 +119,7 @@ struct device *get_device(const char *name, bool create) static const struct device_type simple_type = { .name = "Device", .check_state = system_if_check, - .free = free_device, + .free = free_simple_device, }; struct device *dev; @@ -192,8 +185,21 @@ void remove_device_user(struct device_user *dep) if (list_empty(&dev->users)) { /* all references have gone away, remove this device */ - dev->type->free(dev); + free_device(dev); } dep->dev = NULL; } + +void +cleanup_devices(void) +{ + struct device *dev, *tmp; + + avl_for_each_element_safe(&devices, dev, avl, tmp) { + if (!list_empty(&dev->users)) + continue; + + free_device(dev); + } +}