diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-03-29 02:30:00 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-03-29 02:30:03 +0200 |
commit | c986fc7131d360923908546deab26717a839400d (patch) | |
tree | 9c9b37154fd30a541f3af070bcacb36e9aa6bacc | |
parent | 3444ebe9cb394662241f22efaf7f3eaf9c8c3587 (diff) |
move the device event broadcasts outside of the set_state callback
-rw-r--r-- | device.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -40,15 +40,11 @@ static void broadcast_device_event(struct device *dev, enum device_event ev) static int set_device_state(struct device *dev, bool state) { - if (state) { - broadcast_device_event(dev, DEV_EVENT_SETUP); + if (state) system_if_up(dev); - broadcast_device_event(dev, DEV_EVENT_UP); - } else { - broadcast_device_event(dev, DEV_EVENT_TEARDOWN); + else system_if_down(dev); - broadcast_device_event(dev, DEV_EVENT_DOWN); - } + return 0; } @@ -60,8 +56,11 @@ int claim_device(struct device *dev) if (++dev->active != 1) return 0; + broadcast_device_event(dev, DEV_EVENT_SETUP); ret = dev->set_state(dev, true); - if (ret != 0) + if (ret == 0) + broadcast_device_event(dev, DEV_EVENT_UP); + else dev->active = 0; return ret; @@ -73,8 +72,12 @@ void release_device(struct device *dev) DPRINTF("release device %s, new refcount: %d\n", dev->ifname, dev->active); assert(dev->active >= 0); - if (!dev->active) - dev->set_state(dev, false); + if (dev->active) + return; + + broadcast_device_event(dev, DEV_EVENT_TEARDOWN); + dev->set_state(dev, false); + broadcast_device_event(dev, DEV_EVENT_DOWN); } int check_device_state(struct device *dev) |