[PATCH 2/6] ieee1394 : use class iteration api
Convert to use the class iteration api. Signed-off-by: Dave Young <[EMAIL PROTECTED]> --- drivers/ieee1394/nodemgr.c | 312 + 1 file changed, 175 insertions(+), 137 deletions(-) diff -upr linux/drivers/ieee1394/nodemgr.c linux.new/drivers/ieee1394/nodemgr.c --- linux/drivers/ieee1394/nodemgr.c2008-01-16 08:43:35.0 +0800 +++ linux.new/drivers/ieee1394/nodemgr.c2008-01-16 08:43:35.0 +0800 @@ -727,33 +727,31 @@ static int nodemgr_bus_match(struct devi static DEFINE_MUTEX(nodemgr_serialize_remove_uds); +static int __match_ne(struct device *dev, void *data) +{ + struct unit_directory *ud; + struct node_entry *ne = (struct node_entry *)data; + + ud = container_of(dev, struct unit_directory, unit_dev); + return ud->ne == ne; +} + static void nodemgr_remove_uds(struct node_entry *ne) { struct device *dev; - struct unit_directory *tmp, *ud; + struct unit_directory *ud; - /* Iteration over nodemgr_ud_class.devices has to be protected by -* nodemgr_ud_class.sem, but device_unregister() will eventually -* take nodemgr_ud_class.sem too. Therefore pick out one ud at a time, -* release the semaphore, and then unregister the ud. Since this code -* may be called from other contexts besides the knodemgrds, protect the -* gap after release of the semaphore by nodemgr_serialize_remove_uds. + /* Use class_find device to iterate the devices. Since this code +* may be called from other contexts besides the knodemgrds, +* protect it by nodemgr_serialize_remove_uds. */ mutex_lock(_serialize_remove_uds); for (;;) { - ud = NULL; - down(_ud_class.sem); - list_for_each_entry(dev, _ud_class.devices, node) { - tmp = container_of(dev, struct unit_directory, - unit_dev); - if (tmp->ne == ne) { - ud = tmp; - break; - } - } - up(_ud_class.sem); - if (ud == NULL) + dev = class_find_device(_ud_class, ne, __match_ne); + if (!dev) break; + ud = container_of(dev, struct unit_directory, unit_dev); + put_device(dev); device_unregister(>unit_dev); device_unregister(>device); } @@ -882,45 +880,66 @@ fail_alloc: return NULL; } +static int __match_ne_guid(struct device *dev, void *data) +{ + struct node_entry *ne; + u64 *guid = (u64 *)data; + + ne = container_of(dev, struct node_entry, node_dev); + return ne->guid == *guid; +} static struct node_entry *find_entry_by_guid(u64 guid) { struct device *dev; - struct node_entry *ne, *ret_ne = NULL; - - down(_ne_class.sem); - list_for_each_entry(dev, _ne_class.devices, node) { - ne = container_of(dev, struct node_entry, node_dev); + struct node_entry *ne; - if (ne->guid == guid) { - ret_ne = ne; - break; - } - } - up(_ne_class.sem); + dev = class_find_device(_ne_class, , __match_ne_guid); + if (!dev) + return NULL; + ne = container_of(dev, struct node_entry, node_dev); + put_device(dev); - return ret_ne; + return ne; } +struct match_nodeid_param { + struct hpsb_host *host; + nodeid_t nodeid; +}; + +static int __match_ne_nodeid(struct device *dev, void *data) +{ + int found = 0; + struct node_entry *ne; + struct match_nodeid_param *param = (struct match_nodeid_param *)data; + + if (!dev) + goto ret; + ne = container_of(dev, struct node_entry, node_dev); + if (ne->host == param->host && ne->nodeid == param->nodeid) + found = 1; +ret: + return found; +} static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid) { struct device *dev; - struct node_entry *ne, *ret_ne = NULL; + struct node_entry *ne; + struct match_nodeid_param param; - down(_ne_class.sem); - list_for_each_entry(dev, _ne_class.devices, node) { - ne = container_of(dev, struct node_entry, node_dev); + param.host = host; + param.nodeid = nodeid; - if (ne->host == host && ne->nodeid == nodeid) { - ret_ne = ne; - break; - } - } - up(_ne_class.sem); + dev = class_find_device(_ne_class, , __match_ne_nodeid); + if (!dev) + return NULL; + ne = container_of(dev, struct node_entry, node_dev); +
[PATCH 2/6] ieee1394 : use class iteration api
Convert to use the class iteration api. Signed-off-by: Dave Young [EMAIL PROTECTED] --- drivers/ieee1394/nodemgr.c | 312 + 1 file changed, 175 insertions(+), 137 deletions(-) diff -upr linux/drivers/ieee1394/nodemgr.c linux.new/drivers/ieee1394/nodemgr.c --- linux/drivers/ieee1394/nodemgr.c2008-01-16 08:43:35.0 +0800 +++ linux.new/drivers/ieee1394/nodemgr.c2008-01-16 08:43:35.0 +0800 @@ -727,33 +727,31 @@ static int nodemgr_bus_match(struct devi static DEFINE_MUTEX(nodemgr_serialize_remove_uds); +static int __match_ne(struct device *dev, void *data) +{ + struct unit_directory *ud; + struct node_entry *ne = (struct node_entry *)data; + + ud = container_of(dev, struct unit_directory, unit_dev); + return ud-ne == ne; +} + static void nodemgr_remove_uds(struct node_entry *ne) { struct device *dev; - struct unit_directory *tmp, *ud; + struct unit_directory *ud; - /* Iteration over nodemgr_ud_class.devices has to be protected by -* nodemgr_ud_class.sem, but device_unregister() will eventually -* take nodemgr_ud_class.sem too. Therefore pick out one ud at a time, -* release the semaphore, and then unregister the ud. Since this code -* may be called from other contexts besides the knodemgrds, protect the -* gap after release of the semaphore by nodemgr_serialize_remove_uds. + /* Use class_find device to iterate the devices. Since this code +* may be called from other contexts besides the knodemgrds, +* protect it by nodemgr_serialize_remove_uds. */ mutex_lock(nodemgr_serialize_remove_uds); for (;;) { - ud = NULL; - down(nodemgr_ud_class.sem); - list_for_each_entry(dev, nodemgr_ud_class.devices, node) { - tmp = container_of(dev, struct unit_directory, - unit_dev); - if (tmp-ne == ne) { - ud = tmp; - break; - } - } - up(nodemgr_ud_class.sem); - if (ud == NULL) + dev = class_find_device(nodemgr_ud_class, ne, __match_ne); + if (!dev) break; + ud = container_of(dev, struct unit_directory, unit_dev); + put_device(dev); device_unregister(ud-unit_dev); device_unregister(ud-device); } @@ -882,45 +880,66 @@ fail_alloc: return NULL; } +static int __match_ne_guid(struct device *dev, void *data) +{ + struct node_entry *ne; + u64 *guid = (u64 *)data; + + ne = container_of(dev, struct node_entry, node_dev); + return ne-guid == *guid; +} static struct node_entry *find_entry_by_guid(u64 guid) { struct device *dev; - struct node_entry *ne, *ret_ne = NULL; - - down(nodemgr_ne_class.sem); - list_for_each_entry(dev, nodemgr_ne_class.devices, node) { - ne = container_of(dev, struct node_entry, node_dev); + struct node_entry *ne; - if (ne-guid == guid) { - ret_ne = ne; - break; - } - } - up(nodemgr_ne_class.sem); + dev = class_find_device(nodemgr_ne_class, guid, __match_ne_guid); + if (!dev) + return NULL; + ne = container_of(dev, struct node_entry, node_dev); + put_device(dev); - return ret_ne; + return ne; } +struct match_nodeid_param { + struct hpsb_host *host; + nodeid_t nodeid; +}; + +static int __match_ne_nodeid(struct device *dev, void *data) +{ + int found = 0; + struct node_entry *ne; + struct match_nodeid_param *param = (struct match_nodeid_param *)data; + + if (!dev) + goto ret; + ne = container_of(dev, struct node_entry, node_dev); + if (ne-host == param-host ne-nodeid == param-nodeid) + found = 1; +ret: + return found; +} static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid) { struct device *dev; - struct node_entry *ne, *ret_ne = NULL; + struct node_entry *ne; + struct match_nodeid_param param; - down(nodemgr_ne_class.sem); - list_for_each_entry(dev, nodemgr_ne_class.devices, node) { - ne = container_of(dev, struct node_entry, node_dev); + param.host = host; + param.nodeid = nodeid; - if (ne-host == host ne-nodeid == nodeid) { - ret_ne = ne; - break; - } - } - up(nodemgr_ne_class.sem); + dev = class_find_device(nodemgr_ne_class, param, __match_ne_nodeid); + if (!dev) +