X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=device.c;h=91a78670e6099f7799e6a4c89ade2dc7b1f60e4c;hp=f9ad25aae3d261161b32e4bd84cc8ec26f3a6e77;hb=172bb90bce0354ed9a2d1e62bbe3daee45b32058;hpb=5bf6467af8d59d0b0794413204ad385367221e22 diff --git a/device.c b/device.c index f9ad25a..91a7867 100644 --- a/device.c +++ b/device.c @@ -99,7 +99,7 @@ device_init_settings(struct device *dev, struct blob_attr **tb) static void __init dev_init(void) { - avl_init(&devices, avl_strcmp, false, NULL); + avl_init(&devices, avl_strcmp, true, NULL); } static void device_broadcast_event(struct device *dev, enum device_event ev) @@ -337,8 +337,8 @@ device_replace(struct device *dev, struct device *odev) device_set_present(odev, false); list_for_each_entry_safe(dep, tmp, &odev->users, list) { - list_move_tail(&dep->list, &dev->users); - dep->dev = dev; + device_remove_user(dep); + device_add_user(dep, dev); } device_free(odev); @@ -353,19 +353,25 @@ device_create(const char *name, const struct device_type *type, struct device *odev = NULL, *dev; enum dev_change_type change; + D(DEVICE, "Create new device '%s' (%s)\n", name, type->name); + config = config_memdup(config); + if (!config) + return NULL; + odev = device_get(name, false); if (odev) { change = device_check_config(odev, config); switch (change) { case DEV_CONFIG_APPLIED: free(odev->config); - odev->config = config_memdup(config); + odev->config = config; if (odev->present) { device_set_present(odev, false); device_set_present(odev, true); } /* fall through */ case DEV_CONFIG_NO_CHANGE: + free(config); return odev; case DEV_CONFIG_RECREATE: break; @@ -373,7 +379,7 @@ device_create(const char *name, const struct device_type *type, } dev = type->create(config); - dev->config = config_memdup(config); + dev->config = config; if (odev) device_replace(dev, odev);