aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/attribute_container.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/attribute_container.c')
-rw-r--r--drivers/base/attribute_container.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index ec615d854be9..ebcae5c34133 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -58,6 +58,7 @@ attribute_container_register(struct attribute_container *cont)
58{ 58{
59 INIT_LIST_HEAD(&cont->node); 59 INIT_LIST_HEAD(&cont->node);
60 INIT_LIST_HEAD(&cont->containers); 60 INIT_LIST_HEAD(&cont->containers);
61 spin_lock_init(&cont->containers_lock);
61 62
62 down(&attribute_container_mutex); 63 down(&attribute_container_mutex);
63 list_add_tail(&cont->node, &attribute_container_list); 64 list_add_tail(&cont->node, &attribute_container_list);
@@ -77,11 +78,13 @@ attribute_container_unregister(struct attribute_container *cont)
77{ 78{
78 int retval = -EBUSY; 79 int retval = -EBUSY;
79 down(&attribute_container_mutex); 80 down(&attribute_container_mutex);
81 spin_lock(&cont->containers_lock);
80 if (!list_empty(&cont->containers)) 82 if (!list_empty(&cont->containers))
81 goto out; 83 goto out;
82 retval = 0; 84 retval = 0;
83 list_del(&cont->node); 85 list_del(&cont->node);
84 out: 86 out:
87 spin_unlock(&cont->containers_lock);
85 up(&attribute_container_mutex); 88 up(&attribute_container_mutex);
86 return retval; 89 return retval;
87 90
@@ -151,7 +154,9 @@ attribute_container_add_device(struct device *dev,
151 fn(cont, dev, &ic->classdev); 154 fn(cont, dev, &ic->classdev);
152 else 155 else
153 attribute_container_add_class_device(&ic->classdev); 156 attribute_container_add_class_device(&ic->classdev);
157 spin_lock(&cont->containers_lock);
154 list_add_tail(&ic->node, &cont->containers); 158 list_add_tail(&ic->node, &cont->containers);
159 spin_unlock(&cont->containers_lock);
155 } 160 }
156 up(&attribute_container_mutex); 161 up(&attribute_container_mutex);
157} 162}
@@ -189,6 +194,7 @@ attribute_container_remove_device(struct device *dev,
189 194
190 if (!cont->match(cont, dev)) 195 if (!cont->match(cont, dev))
191 continue; 196 continue;
197 spin_lock(&cont->containers_lock);
192 list_for_each_entry_safe(ic, tmp, &cont->containers, node) { 198 list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
193 if (dev != ic->classdev.dev) 199 if (dev != ic->classdev.dev)
194 continue; 200 continue;
@@ -200,6 +206,7 @@ attribute_container_remove_device(struct device *dev,
200 class_device_unregister(&ic->classdev); 206 class_device_unregister(&ic->classdev);
201 } 207 }
202 } 208 }
209 spin_unlock(&cont->containers_lock);
203 } 210 }
204 up(&attribute_container_mutex); 211 up(&attribute_container_mutex);
205} 212}
@@ -230,10 +237,17 @@ attribute_container_device_trigger(struct device *dev,
230 if (!cont->match(cont, dev)) 237 if (!cont->match(cont, dev))
231 continue; 238 continue;
232 239
240 if (attribute_container_no_classdevs(cont)) {
241 fn(cont, dev, NULL);
242 continue;
243 }
244
245 spin_lock(&cont->containers_lock);
233 list_for_each_entry_safe(ic, tmp, &cont->containers, node) { 246 list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
234 if (dev == ic->classdev.dev) 247 if (dev == ic->classdev.dev)
235 fn(cont, dev, &ic->classdev); 248 fn(cont, dev, &ic->classdev);
236 } 249 }
250 spin_unlock(&cont->containers_lock);
237 } 251 }
238 up(&attribute_container_mutex); 252 up(&attribute_container_mutex);
239} 253}
@@ -368,6 +382,35 @@ attribute_container_class_device_del(struct class_device *classdev)
368} 382}
369EXPORT_SYMBOL_GPL(attribute_container_class_device_del); 383EXPORT_SYMBOL_GPL(attribute_container_class_device_del);
370 384
385/**
386 * attribute_container_find_class_device - find the corresponding class_device
387 *
388 * @cont: the container
389 * @dev: the generic device
390 *
391 * Looks up the device in the container's list of class devices and returns
392 * the corresponding class_device.
393 */
394struct class_device *
395attribute_container_find_class_device(struct attribute_container *cont,
396 struct device *dev)
397{
398 struct class_device *cdev = NULL;
399 struct internal_container *ic;
400
401 spin_lock(&cont->containers_lock);
402 list_for_each_entry(ic, &cont->containers, node) {
403 if (ic->classdev.dev == dev) {
404 cdev = &ic->classdev;
405 break;
406 }
407 }
408 spin_unlock(&cont->containers_lock);
409
410 return cdev;
411}
412EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
413
371int __init 414int __init
372attribute_container_init(void) 415attribute_container_init(void)
373{ 416{