summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorJames Bottomley <jejb@titanic.(none)>2005-09-06 17:52:54 -0500
committerJames Bottomley <jejb@titanic.(none)>2005-09-06 17:52:54 -0500
commit17fa53da1239b8712c5cebbd72a74c713b6c2db9 (patch)
tree8cf55e47ce681a6c899ccf8e06abeccecb20d38b /drivers/base
parent3173d8c342971a03857d8af749a3f57da7d06b57 (diff)
parentfe1b2d544d71300f8e2d151c3c77a130d13a58be (diff)
downloadop-kernel-dev-17fa53da1239b8712c5cebbd72a74c713b6c2db9.zip
op-kernel-dev-17fa53da1239b8712c5cebbd72a74c713b6c2db9.tar.gz
Merge by hand (conflicts in sd.c)
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/attribute_container.c67
1 files changed, 45 insertions, 22 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index ebcae5c..373e7b7 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -22,11 +22,26 @@
/* This is a private structure used to tie the classdev and the
* container .. it should never be visible outside this file */
struct internal_container {
- struct list_head node;
+ struct klist_node node;
struct attribute_container *cont;
struct class_device classdev;
};
+static void internal_container_klist_get(struct klist_node *n)
+{
+ struct internal_container *ic =
+ container_of(n, struct internal_container, node);
+ class_device_get(&ic->classdev);
+}
+
+static void internal_container_klist_put(struct klist_node *n)
+{
+ struct internal_container *ic =
+ container_of(n, struct internal_container, node);
+ class_device_put(&ic->classdev);
+}
+
+
/**
* attribute_container_classdev_to_container - given a classdev, return the container
*
@@ -57,8 +72,8 @@ int
attribute_container_register(struct attribute_container *cont)
{
INIT_LIST_HEAD(&cont->node);
- INIT_LIST_HEAD(&cont->containers);
- spin_lock_init(&cont->containers_lock);
+ klist_init(&cont->containers,internal_container_klist_get,
+ internal_container_klist_put);
down(&attribute_container_mutex);
list_add_tail(&cont->node, &attribute_container_list);
@@ -78,13 +93,13 @@ attribute_container_unregister(struct attribute_container *cont)
{
int retval = -EBUSY;
down(&attribute_container_mutex);
- spin_lock(&cont->containers_lock);
- if (!list_empty(&cont->containers))
+ spin_lock(&cont->containers.k_lock);
+ if (!list_empty(&cont->containers.k_list))
goto out;
retval = 0;
list_del(&cont->node);
out:
- spin_unlock(&cont->containers_lock);
+ spin_unlock(&cont->containers.k_lock);
up(&attribute_container_mutex);
return retval;
@@ -143,7 +158,6 @@ attribute_container_add_device(struct device *dev,
continue;
}
memset(ic, 0, sizeof(struct internal_container));
- INIT_LIST_HEAD(&ic->node);
ic->cont = cont;
class_device_initialize(&ic->classdev);
ic->classdev.dev = get_device(dev);
@@ -154,13 +168,22 @@ attribute_container_add_device(struct device *dev,
fn(cont, dev, &ic->classdev);
else
attribute_container_add_class_device(&ic->classdev);
- spin_lock(&cont->containers_lock);
- list_add_tail(&ic->node, &cont->containers);
- spin_unlock(&cont->containers_lock);
+ klist_add_tail(&ic->node, &cont->containers);
}
up(&attribute_container_mutex);
}
+/* FIXME: can't break out of this unless klist_iter_exit is also
+ * called before doing the break
+ */
+#define klist_for_each_entry(pos, head, member, iter) \
+ for (klist_iter_init(head, iter); (pos = ({ \
+ struct klist_node *n = klist_next(iter); \
+ n ? container_of(n, typeof(*pos), member) : \
+ ({ klist_iter_exit(iter) ; NULL; }); \
+ }) ) != NULL; )
+
+
/**
* attribute_container_remove_device - make device eligible for removal.
*
@@ -187,18 +210,19 @@ attribute_container_remove_device(struct device *dev,
down(&attribute_container_mutex);
list_for_each_entry(cont, &attribute_container_list, node) {
- struct internal_container *ic, *tmp;
+ struct internal_container *ic;
+ struct klist_iter iter;
if (attribute_container_no_classdevs(cont))
continue;
if (!cont->match(cont, dev))
continue;
- spin_lock(&cont->containers_lock);
- list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
+
+ klist_for_each_entry(ic, &cont->containers, node, &iter) {
if (dev != ic->classdev.dev)
continue;
- list_del(&ic->node);
+ klist_del(&ic->node);
if (fn)
fn(cont, dev, &ic->classdev);
else {
@@ -206,7 +230,6 @@ attribute_container_remove_device(struct device *dev,
class_device_unregister(&ic->classdev);
}
}
- spin_unlock(&cont->containers_lock);
}
up(&attribute_container_mutex);
}
@@ -232,7 +255,8 @@ attribute_container_device_trigger(struct device *dev,
down(&attribute_container_mutex);
list_for_each_entry(cont, &attribute_container_list, node) {
- struct internal_container *ic, *tmp;
+ struct internal_container *ic;
+ struct klist_iter iter;
if (!cont->match(cont, dev))
continue;
@@ -242,12 +266,10 @@ attribute_container_device_trigger(struct device *dev,
continue;
}
- spin_lock(&cont->containers_lock);
- list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
+ klist_for_each_entry(ic, &cont->containers, node, &iter) {
if (dev == ic->classdev.dev)
fn(cont, dev, &ic->classdev);
}
- spin_unlock(&cont->containers_lock);
}
up(&attribute_container_mutex);
}
@@ -397,15 +419,16 @@ attribute_container_find_class_device(struct attribute_container *cont,
{
struct class_device *cdev = NULL;
struct internal_container *ic;
+ struct klist_iter iter;
- spin_lock(&cont->containers_lock);
- list_for_each_entry(ic, &cont->containers, node) {
+ klist_for_each_entry(ic, &cont->containers, node, &iter) {
if (ic->classdev.dev == dev) {
cdev = &ic->classdev;
+ /* FIXME: must exit iterator then break */
+ klist_iter_exit(&iter);
break;
}
}
- spin_unlock(&cont->containers_lock);
return cdev;
}
OpenPOWER on IntegriCloud