diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/attribute_container.c | 38 | ||||
-rw-r--r-- | drivers/base/transport_class.c | 17 |
2 files changed, 49 insertions, 6 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index ec615d854be9..62c093db11e6 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,12 @@ 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 | spin_lock(&cont->containers_lock); | ||
233 | list_for_each_entry_safe(ic, tmp, &cont->containers, node) { | 241 | list_for_each_entry_safe(ic, tmp, &cont->containers, node) { |
234 | if (dev == ic->classdev.dev) | 242 | if (dev == ic->classdev.dev) |
235 | fn(cont, dev, &ic->classdev); | 243 | fn(cont, dev, &ic->classdev); |
236 | } | 244 | } |
245 | spin_unlock(&cont->containers_lock); | ||
237 | } | 246 | } |
238 | up(&attribute_container_mutex); | 247 | up(&attribute_container_mutex); |
239 | } | 248 | } |
@@ -368,6 +377,35 @@ attribute_container_class_device_del(struct class_device *classdev) | |||
368 | } | 377 | } |
369 | EXPORT_SYMBOL_GPL(attribute_container_class_device_del); | 378 | EXPORT_SYMBOL_GPL(attribute_container_class_device_del); |
370 | 379 | ||
380 | /** | ||
381 | * attribute_container_find_class_device - find the corresponding class_device | ||
382 | * | ||
383 | * @cont: the container | ||
384 | * @dev: the generic device | ||
385 | * | ||
386 | * Looks up the device in the container's list of class devices and returns | ||
387 | * the corresponding class_device. | ||
388 | */ | ||
389 | struct class_device * | ||
390 | attribute_container_find_class_device(struct attribute_container *cont, | ||
391 | struct device *dev) | ||
392 | { | ||
393 | struct class_device *cdev = NULL; | ||
394 | struct internal_container *ic; | ||
395 | |||
396 | spin_lock(&cont->containers_lock); | ||
397 | list_for_each_entry(ic, &cont->containers, node) { | ||
398 | if (ic->classdev.dev == dev) { | ||
399 | cdev = &ic->classdev; | ||
400 | break; | ||
401 | } | ||
402 | } | ||
403 | spin_unlock(&cont->containers_lock); | ||
404 | |||
405 | return cdev; | ||
406 | } | ||
407 | EXPORT_SYMBOL_GPL(attribute_container_find_class_device); | ||
408 | |||
371 | int __init | 409 | int __init |
372 | attribute_container_init(void) | 410 | attribute_container_init(void) |
373 | { | 411 | { |
diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c index 6c2b447a3336..4fb4c5de8470 100644 --- a/drivers/base/transport_class.c +++ b/drivers/base/transport_class.c | |||
@@ -64,7 +64,9 @@ void transport_class_unregister(struct transport_class *tclass) | |||
64 | } | 64 | } |
65 | EXPORT_SYMBOL_GPL(transport_class_unregister); | 65 | EXPORT_SYMBOL_GPL(transport_class_unregister); |
66 | 66 | ||
67 | static int anon_transport_dummy_function(struct device *dev) | 67 | static int anon_transport_dummy_function(struct transport_container *tc, |
68 | struct device *dev, | ||
69 | struct class_device *cdev) | ||
68 | { | 70 | { |
69 | /* do nothing */ | 71 | /* do nothing */ |
70 | return 0; | 72 | return 0; |
@@ -115,9 +117,10 @@ static int transport_setup_classdev(struct attribute_container *cont, | |||
115 | struct class_device *classdev) | 117 | struct class_device *classdev) |
116 | { | 118 | { |
117 | struct transport_class *tclass = class_to_transport_class(cont->class); | 119 | struct transport_class *tclass = class_to_transport_class(cont->class); |
120 | struct transport_container *tcont = attribute_container_to_transport_container(cont); | ||
118 | 121 | ||
119 | if (tclass->setup) | 122 | if (tclass->setup) |
120 | tclass->setup(dev); | 123 | tclass->setup(tcont, dev, classdev); |
121 | 124 | ||
122 | return 0; | 125 | return 0; |
123 | } | 126 | } |
@@ -178,12 +181,14 @@ void transport_add_device(struct device *dev) | |||
178 | EXPORT_SYMBOL_GPL(transport_add_device); | 181 | EXPORT_SYMBOL_GPL(transport_add_device); |
179 | 182 | ||
180 | static int transport_configure(struct attribute_container *cont, | 183 | static int transport_configure(struct attribute_container *cont, |
181 | struct device *dev) | 184 | struct device *dev, |
185 | struct class_device *cdev) | ||
182 | { | 186 | { |
183 | struct transport_class *tclass = class_to_transport_class(cont->class); | 187 | struct transport_class *tclass = class_to_transport_class(cont->class); |
188 | struct transport_container *tcont = attribute_container_to_transport_container(cont); | ||
184 | 189 | ||
185 | if (tclass->configure) | 190 | if (tclass->configure) |
186 | tclass->configure(dev); | 191 | tclass->configure(tcont, dev, cdev); |
187 | 192 | ||
188 | return 0; | 193 | return 0; |
189 | } | 194 | } |
@@ -202,7 +207,7 @@ static int transport_configure(struct attribute_container *cont, | |||
202 | */ | 207 | */ |
203 | void transport_configure_device(struct device *dev) | 208 | void transport_configure_device(struct device *dev) |
204 | { | 209 | { |
205 | attribute_container_trigger(dev, transport_configure); | 210 | attribute_container_device_trigger(dev, transport_configure); |
206 | } | 211 | } |
207 | EXPORT_SYMBOL_GPL(transport_configure_device); | 212 | EXPORT_SYMBOL_GPL(transport_configure_device); |
208 | 213 | ||
@@ -215,7 +220,7 @@ static int transport_remove_classdev(struct attribute_container *cont, | |||
215 | struct transport_class *tclass = class_to_transport_class(cont->class); | 220 | struct transport_class *tclass = class_to_transport_class(cont->class); |
216 | 221 | ||
217 | if (tclass->remove) | 222 | if (tclass->remove) |
218 | tclass->remove(dev); | 223 | tclass->remove(tcont, dev, classdev); |
219 | 224 | ||
220 | if (tclass->remove != anon_transport_dummy_function) { | 225 | if (tclass->remove != anon_transport_dummy_function) { |
221 | if (tcont->statistics) | 226 | if (tcont->statistics) |