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)
{
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);
static const struct device_type simple_type = {
.name = "Device",
.check_state = system_if_check,
- .free = free_device,
+ .free = free_simple_device,
};
struct device *dev;
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);
+ }
+}