summaryrefslogtreecommitdiffhomepage
path: root/device.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-03-27 18:40:01 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-03-27 18:40:01 +0200
commit5483940df7a35d052d195a2fa1db29763f795ad0 (patch)
treea4ea566ef079b54836dc810b14bd7bfd94d6c566 /device.c
parent0b7be79bc1fe58c0c19c0c21b1200b098186432f (diff)
add a function for adding a virtual device (not tracked in the avl tree)
Diffstat (limited to 'device.c')
-rw-r--r--device.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/device.c b/device.c
index e1ffba1..f9cb058 100644
--- a/device.c
+++ b/device.c
@@ -85,29 +85,36 @@ int check_device_state(struct device *dev)
return dev->type->check_state(dev);
}
-int init_device(struct device *dev, const struct device_type *type, const char *ifname)
+void init_virtual_device(struct device *dev, const struct device_type *type, const char *name)
{
- int ret;
-
assert(dev);
assert(type);
- if (ifname)
- strncpy(dev->ifname, ifname, IFNAMSIZ);
+ fprintf(stderr, "Initialize interface '%s'\n", dev->ifname);
+ INIT_LIST_HEAD(&dev->users);
+ dev->type = type;
+
+ if (name)
+ strncpy(dev->ifname, name, IFNAMSIZ);
+}
+
+int init_device(struct device *dev, const struct device_type *type, const char *ifname)
+{
+ int ret;
+
+ init_virtual_device(dev, type, ifname);
if (!dev->set_state)
dev->set_state = set_device_state;
- fprintf(stderr, "Initialize interface '%s'\n", dev->ifname);
- INIT_LIST_HEAD(&dev->users);
dev->avl.key = dev->ifname;
- dev->type = type;
ret = avl_insert(&devices, &dev->avl);
if (ret < 0)
return ret;
check_device_state(dev);
+
return 0;
}
@@ -149,7 +156,8 @@ void cleanup_device(struct device *dev)
dep->cb(dep, DEV_EVENT_REMOVE);
}
- avl_delete(&devices, &dev->avl);
+ if (dev->avl.key)
+ avl_delete(&devices, &dev->avl);
}
void set_device_present(struct device *dev, bool state)