From 51b3f21fef7f581a7df6d8a73d8b973f9eb355d2 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 5 Jul 2012 20:28:31 +0200 Subject: alias: use a callback for managing device presence state, track alias deps in a separate list to avoid recursion issues --- alias.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'alias.c') diff --git a/alias.c b/alias.c index 338ece6..07ed5fe 100644 --- a/alias.c +++ b/alias.c @@ -48,6 +48,24 @@ alias_device_set_state(struct device *dev, bool state) return 0; } +static void alias_device_cb(struct device_user *dep, enum device_event ev) +{ + struct alias_device *alias; + bool present = false; + + alias = container_of(dep, struct alias_device, dep); + switch (ev) { + case DEV_EVENT_ADD: + present = true; + case DEV_EVENT_REMOVE: + device_set_present(&alias->dev, present); + break; + default: + device_broadcast_event(&alias->dev, ev); + break; + } +} + static struct device * alias_device_create(const char *name, struct blob_attr *attr) { @@ -60,6 +78,8 @@ alias_device_create(const char *name, struct blob_attr *attr) device_init_virtual(&alias->dev, &alias_device_type, NULL); alias->avl.key = alias->name; avl_insert(&aliases, &alias->avl); + alias->dep.alias = true; + alias->dep.cb = alias_device_cb; return &alias->dev; } @@ -101,8 +121,6 @@ alias_notify_device(const char *name, struct device *dev) } } - device_set_present(&alias->dev, !!dev); - if (!dev && alias->dep.dev && !alias->dep.dev->active) { device_remove_user(&alias->dep); alias->dev.hidden = true; -- cgit v1.2.3