summaryrefslogtreecommitdiffhomepage
path: root/device.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-06 03:24:23 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-06 03:25:33 +0200
commit273eb40f725de67011c092d2ed9f07a2d7f84ac3 (patch)
treebfc4958c931bfd8980b917da6db8b1880a60119c /device.c
parentbeaf1b3d4ad313522bdd02f4c561dca94360bd46 (diff)
fix refcount bugs when dev->set_state fails
Diffstat (limited to 'device.c')
-rw-r--r--device.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/device.c b/device.c
index 44541e2..32fa4a4 100644
--- a/device.c
+++ b/device.c
@@ -141,8 +141,11 @@ int device_claim(struct device_user *dep)
ret = dev->set_state(dev, true);
if (ret == 0)
device_broadcast_event(dev, DEV_EVENT_UP);
- else
+ else {
+ D(DEVICE, "claim device %s failed: %d\n", dev->ifname, ret);
dev->active = 0;
+ dep->claimed = false;
+ }
return ret;
}
@@ -259,6 +262,7 @@ void device_cleanup(struct device *dev)
continue;
dep->cb(dep, DEV_EVENT_REMOVE);
+ device_release(dep);
}
device_delete(dev);
@@ -379,8 +383,9 @@ device_replace(struct device *dev, struct device *odev)
device_set_present(odev, false);
list_for_each_entry_safe(dep, tmp, &odev->users, list) {
- device_remove_user(dep);
- device_add_user(dep, dev);
+ device_release(dep);
+ list_move_tail(&dep->list, &dev->users);
+ dep->dev = dev;
}
device_free(odev);