diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-03-03 20:21:53 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-03-03 20:21:53 +0100 |
commit | aff73720b65ca33a487c813f27644f8d5aea0df1 (patch) | |
tree | 9b79403548c302dd417b712ac61ffb3cb0c4d69e /interface.c | |
parent | 93ddba72304f8267f8ca63dce2235a154227cd99 (diff) |
ubus: use interface_{add,remove}_link for hotplug ops
Diffstat (limited to 'interface.c')
-rw-r--r-- | interface.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/interface.c b/interface.c index 3dceef0..2404878 100644 --- a/interface.c +++ b/interface.c @@ -351,17 +351,22 @@ interface_add(struct interface *iface, struct blob_attr *config) vlist_add(&interfaces, &iface->node); } -void +int interface_remove_link(struct interface *iface, struct device *dev) { struct device *mdev = iface->main_dev.dev; - if (mdev && mdev->hotplug_ops) { - mdev->hotplug_ops->del(mdev, dev); - return; - } + if (mdev && mdev->hotplug_ops) + return mdev->hotplug_ops->del(mdev, dev); + + if (!iface->main_dev.hotplug) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (dev != iface->main_dev.dev) + return UBUS_STATUS_INVALID_ARGUMENT; device_remove_user(&iface->main_dev); + return 0; } int @@ -369,14 +374,21 @@ interface_add_link(struct interface *iface, struct device *dev) { struct device *mdev = iface->main_dev.dev; - if (mdev && mdev->hotplug_ops) - return mdev->hotplug_ops->add(mdev, dev); + if (mdev == dev) + return 0; - if (iface->main_dev.dev) - interface_remove_link(iface, NULL); + if (iface->main_dev.hotplug) + device_remove_user(&iface->main_dev); - device_add_user(&iface->main_dev, dev); + if (mdev) { + if (mdev->hotplug_ops) + return mdev->hotplug_ops->add(mdev, dev); + else + return UBUS_STATUS_NOT_SUPPORTED; + } + device_add_user(&iface->main_dev, dev); + iface->main_dev.hotplug = true; return 0; } |