From: Felix Fietkau Date: Mon, 5 Sep 2011 01:56:10 +0000 (+0200) Subject: fix the ubus hotplug add/remove interface to properly clean up devices X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=commitdiff_plain;h=f5bb1c61228b7900e69eaea0788ee9d5fb304691 fix the ubus hotplug add/remove interface to properly clean up devices --- diff --git a/ubus.c b/ubus.c index 8b9bc3a..2c4e4e6 100644 --- a/ubus.c +++ b/ubus.c @@ -207,33 +207,35 @@ netifd_iface_handle_device(struct ubus_context *ctx, struct ubus_object *obj, if (!tb[DEV_NAME]) return UBUS_STATUS_INVALID_ARGUMENT; - dev = device_get(blobmsg_data(tb[DEV_NAME]), add); - if (!dev) - return UBUS_STATUS_NOT_FOUND; - main_dev = iface->main_dev.dev; if (!main_dev) return UBUS_STATUS_NOT_FOUND; - if (main_dev == dev) - return UBUS_STATUS_INVALID_ARGUMENT; - if (!main_dev->hotplug_ops) return UBUS_STATUS_NOT_SUPPORTED; - if (add) - ret = main_dev->hotplug_ops->add(main_dev, dev); - else - ret = main_dev->hotplug_ops->del(main_dev, dev); + dev = device_get(blobmsg_data(tb[DEV_NAME]), add); + if (!dev) + return UBUS_STATUS_NOT_FOUND; + + if (main_dev != dev) { + if (add) + ret = main_dev->hotplug_ops->add(main_dev, dev); + else + ret = main_dev->hotplug_ops->del(main_dev, dev); + if (ret) + ret = UBUS_STATUS_UNKNOWN_ERROR; + } else { + ret = UBUS_STATUS_INVALID_ARGUMENT; + } - if (ret) - return UBUS_STATUS_UNKNOWN_ERROR; + if (add) + device_free_unused(dev); - return 0; + return ret; } - static struct ubus_method iface_object_methods[] = { { .name = "up", .handler = netifd_handle_up }, { .name = "down", .handler = netifd_handle_down },