Loading...
1/*
2 * attribute_container.c - implementation of a simple container for classes
3 *
4 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
5 *
6 * This file is licensed under GPLv2
7 *
8 * The basic idea here is to enable a device to be attached to an
9 * aritrary numer of classes without having to allocate storage for them.
10 * Instead, the contained classes select the devices they need to attach
11 * to via a matching function.
12 */
13
14#include <linux/attribute_container.h>
15#include <linux/init.h>
16#include <linux/device.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/list.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22
23#include "base.h"
24
25/* This is a private structure used to tie the classdev and the
26 * container .. it should never be visible outside this file */
27struct internal_container {
28 struct klist_node node;
29 struct attribute_container *cont;
30 struct device classdev;
31};
32
33static void internal_container_klist_get(struct klist_node *n)
34{
35 struct internal_container *ic =
36 container_of(n, struct internal_container, node);
37 get_device(&ic->classdev);
38}
39
40static void internal_container_klist_put(struct klist_node *n)
41{
42 struct internal_container *ic =
43 container_of(n, struct internal_container, node);
44 put_device(&ic->classdev);
45}
46
47
48/**
49 * attribute_container_classdev_to_container - given a classdev, return the container
50 *
51 * @classdev: the class device created by attribute_container_add_device.
52 *
53 * Returns the container associated with this classdev.
54 */
55struct attribute_container *
56attribute_container_classdev_to_container(struct device *classdev)
57{
58 struct internal_container *ic =
59 container_of(classdev, struct internal_container, classdev);
60 return ic->cont;
61}
62EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container);
63
64static LIST_HEAD(attribute_container_list);
65
66static DEFINE_MUTEX(attribute_container_mutex);
67
68/**
69 * attribute_container_register - register an attribute container
70 *
71 * @cont: The container to register. This must be allocated by the
72 * callee and should also be zeroed by it.
73 */
74int
75attribute_container_register(struct attribute_container *cont)
76{
77 INIT_LIST_HEAD(&cont->node);
78 klist_init(&cont->containers,internal_container_klist_get,
79 internal_container_klist_put);
80
81 mutex_lock(&attribute_container_mutex);
82 list_add_tail(&cont->node, &attribute_container_list);
83 mutex_unlock(&attribute_container_mutex);
84
85 return 0;
86}
87EXPORT_SYMBOL_GPL(attribute_container_register);
88
89/**
90 * attribute_container_unregister - remove a container registration
91 *
92 * @cont: previously registered container to remove
93 */
94int
95attribute_container_unregister(struct attribute_container *cont)
96{
97 int retval = -EBUSY;
98 mutex_lock(&attribute_container_mutex);
99 spin_lock(&cont->containers.k_lock);
100 if (!list_empty(&cont->containers.k_list))
101 goto out;
102 retval = 0;
103 list_del(&cont->node);
104 out:
105 spin_unlock(&cont->containers.k_lock);
106 mutex_unlock(&attribute_container_mutex);
107 return retval;
108
109}
110EXPORT_SYMBOL_GPL(attribute_container_unregister);
111
112/* private function used as class release */
113static void attribute_container_release(struct device *classdev)
114{
115 struct internal_container *ic
116 = container_of(classdev, struct internal_container, classdev);
117 struct device *dev = classdev->parent;
118
119 kfree(ic);
120 put_device(dev);
121}
122
123/**
124 * attribute_container_add_device - see if any container is interested in dev
125 *
126 * @dev: device to add attributes to
127 * @fn: function to trigger addition of class device.
128 *
129 * This function allocates storage for the class device(s) to be
130 * attached to dev (one for each matching attribute_container). If no
131 * fn is provided, the code will simply register the class device via
132 * device_add. If a function is provided, it is expected to add
133 * the class device at the appropriate time. One of the things that
134 * might be necessary is to allocate and initialise the classdev and
135 * then add it a later time. To do this, call this routine for
136 * allocation and initialisation and then use
137 * attribute_container_device_trigger() to call device_add() on
138 * it. Note: after this, the class device contains a reference to dev
139 * which is not relinquished until the release of the classdev.
140 */
141void
142attribute_container_add_device(struct device *dev,
143 int (*fn)(struct attribute_container *,
144 struct device *,
145 struct device *))
146{
147 struct attribute_container *cont;
148
149 mutex_lock(&attribute_container_mutex);
150 list_for_each_entry(cont, &attribute_container_list, node) {
151 struct internal_container *ic;
152
153 if (attribute_container_no_classdevs(cont))
154 continue;
155
156 if (!cont->match(cont, dev))
157 continue;
158
159 ic = kzalloc(sizeof(*ic), GFP_KERNEL);
160 if (!ic) {
161 dev_printk(KERN_ERR, dev, "failed to allocate class container\n");
162 continue;
163 }
164
165 ic->cont = cont;
166 device_initialize(&ic->classdev);
167 ic->classdev.parent = get_device(dev);
168 ic->classdev.class = cont->class;
169 cont->class->dev_release = attribute_container_release;
170 dev_set_name(&ic->classdev, dev_name(dev));
171 if (fn)
172 fn(cont, dev, &ic->classdev);
173 else
174 attribute_container_add_class_device(&ic->classdev);
175 klist_add_tail(&ic->node, &cont->containers);
176 }
177 mutex_unlock(&attribute_container_mutex);
178}
179
180/* FIXME: can't break out of this unless klist_iter_exit is also
181 * called before doing the break
182 */
183#define klist_for_each_entry(pos, head, member, iter) \
184 for (klist_iter_init(head, iter); (pos = ({ \
185 struct klist_node *n = klist_next(iter); \
186 n ? container_of(n, typeof(*pos), member) : \
187 ({ klist_iter_exit(iter) ; NULL; }); \
188 }) ) != NULL; )
189
190
191/**
192 * attribute_container_remove_device - make device eligible for removal.
193 *
194 * @dev: The generic device
195 * @fn: A function to call to remove the device
196 *
197 * This routine triggers device removal. If fn is NULL, then it is
198 * simply done via device_unregister (note that if something
199 * still has a reference to the classdev, then the memory occupied
200 * will not be freed until the classdev is released). If you want a
201 * two phase release: remove from visibility and then delete the
202 * device, then you should use this routine with a fn that calls
203 * device_del() and then use attribute_container_device_trigger()
204 * to do the final put on the classdev.
205 */
206void
207attribute_container_remove_device(struct device *dev,
208 void (*fn)(struct attribute_container *,
209 struct device *,
210 struct device *))
211{
212 struct attribute_container *cont;
213
214 mutex_lock(&attribute_container_mutex);
215 list_for_each_entry(cont, &attribute_container_list, node) {
216 struct internal_container *ic;
217 struct klist_iter iter;
218
219 if (attribute_container_no_classdevs(cont))
220 continue;
221
222 if (!cont->match(cont, dev))
223 continue;
224
225 klist_for_each_entry(ic, &cont->containers, node, &iter) {
226 if (dev != ic->classdev.parent)
227 continue;
228 klist_del(&ic->node);
229 if (fn)
230 fn(cont, dev, &ic->classdev);
231 else {
232 attribute_container_remove_attrs(&ic->classdev);
233 device_unregister(&ic->classdev);
234 }
235 }
236 }
237 mutex_unlock(&attribute_container_mutex);
238}
239
240/**
241 * attribute_container_device_trigger - execute a trigger for each matching classdev
242 *
243 * @dev: The generic device to run the trigger for
244 * @fn the function to execute for each classdev.
245 *
246 * This funcion is for executing a trigger when you need to know both
247 * the container and the classdev. If you only care about the
248 * container, then use attribute_container_trigger() instead.
249 */
250void
251attribute_container_device_trigger(struct device *dev,
252 int (*fn)(struct attribute_container *,
253 struct device *,
254 struct device *))
255{
256 struct attribute_container *cont;
257
258 mutex_lock(&attribute_container_mutex);
259 list_for_each_entry(cont, &attribute_container_list, node) {
260 struct internal_container *ic;
261 struct klist_iter iter;
262
263 if (!cont->match(cont, dev))
264 continue;
265
266 if (attribute_container_no_classdevs(cont)) {
267 fn(cont, dev, NULL);
268 continue;
269 }
270
271 klist_for_each_entry(ic, &cont->containers, node, &iter) {
272 if (dev == ic->classdev.parent)
273 fn(cont, dev, &ic->classdev);
274 }
275 }
276 mutex_unlock(&attribute_container_mutex);
277}
278
279/**
280 * attribute_container_trigger - trigger a function for each matching container
281 *
282 * @dev: The generic device to activate the trigger for
283 * @fn: the function to trigger
284 *
285 * This routine triggers a function that only needs to know the
286 * matching containers (not the classdev) associated with a device.
287 * It is more lightweight than attribute_container_device_trigger, so
288 * should be used in preference unless the triggering function
289 * actually needs to know the classdev.
290 */
291void
292attribute_container_trigger(struct device *dev,
293 int (*fn)(struct attribute_container *,
294 struct device *))
295{
296 struct attribute_container *cont;
297
298 mutex_lock(&attribute_container_mutex);
299 list_for_each_entry(cont, &attribute_container_list, node) {
300 if (cont->match(cont, dev))
301 fn(cont, dev);
302 }
303 mutex_unlock(&attribute_container_mutex);
304}
305
306/**
307 * attribute_container_add_attrs - add attributes
308 *
309 * @classdev: The class device
310 *
311 * This simply creates all the class device sysfs files from the
312 * attributes listed in the container
313 */
314int
315attribute_container_add_attrs(struct device *classdev)
316{
317 struct attribute_container *cont =
318 attribute_container_classdev_to_container(classdev);
319 struct device_attribute **attrs = cont->attrs;
320 int i, error;
321
322 BUG_ON(attrs && cont->grp);
323
324 if (!attrs && !cont->grp)
325 return 0;
326
327 if (cont->grp)
328 return sysfs_create_group(&classdev->kobj, cont->grp);
329
330 for (i = 0; attrs[i]; i++) {
331 sysfs_attr_init(&attrs[i]->attr);
332 error = device_create_file(classdev, attrs[i]);
333 if (error)
334 return error;
335 }
336
337 return 0;
338}
339
340/**
341 * attribute_container_add_class_device - same function as device_add
342 *
343 * @classdev: the class device to add
344 *
345 * This performs essentially the same function as device_add except for
346 * attribute containers, namely add the classdev to the system and then
347 * create the attribute files
348 */
349int
350attribute_container_add_class_device(struct device *classdev)
351{
352 int error = device_add(classdev);
353 if (error)
354 return error;
355 return attribute_container_add_attrs(classdev);
356}
357
358/**
359 * attribute_container_add_class_device_adapter - simple adapter for triggers
360 *
361 * This function is identical to attribute_container_add_class_device except
362 * that it is designed to be called from the triggers
363 */
364int
365attribute_container_add_class_device_adapter(struct attribute_container *cont,
366 struct device *dev,
367 struct device *classdev)
368{
369 return attribute_container_add_class_device(classdev);
370}
371
372/**
373 * attribute_container_remove_attrs - remove any attribute files
374 *
375 * @classdev: The class device to remove the files from
376 *
377 */
378void
379attribute_container_remove_attrs(struct device *classdev)
380{
381 struct attribute_container *cont =
382 attribute_container_classdev_to_container(classdev);
383 struct device_attribute **attrs = cont->attrs;
384 int i;
385
386 if (!attrs && !cont->grp)
387 return;
388
389 if (cont->grp) {
390 sysfs_remove_group(&classdev->kobj, cont->grp);
391 return ;
392 }
393
394 for (i = 0; attrs[i]; i++)
395 device_remove_file(classdev, attrs[i]);
396}
397
398/**
399 * attribute_container_class_device_del - equivalent of class_device_del
400 *
401 * @classdev: the class device
402 *
403 * This function simply removes all the attribute files and then calls
404 * device_del.
405 */
406void
407attribute_container_class_device_del(struct device *classdev)
408{
409 attribute_container_remove_attrs(classdev);
410 device_del(classdev);
411}
412
413/**
414 * attribute_container_find_class_device - find the corresponding class_device
415 *
416 * @cont: the container
417 * @dev: the generic device
418 *
419 * Looks up the device in the container's list of class devices and returns
420 * the corresponding class_device.
421 */
422struct device *
423attribute_container_find_class_device(struct attribute_container *cont,
424 struct device *dev)
425{
426 struct device *cdev = NULL;
427 struct internal_container *ic;
428 struct klist_iter iter;
429
430 klist_for_each_entry(ic, &cont->containers, node, &iter) {
431 if (ic->classdev.parent == dev) {
432 cdev = &ic->classdev;
433 /* FIXME: must exit iterator then break */
434 klist_iter_exit(&iter);
435 break;
436 }
437 }
438
439 return cdev;
440}
441EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
1/*
2 * attribute_container.c - implementation of a simple container for classes
3 *
4 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
5 *
6 * This file is licensed under GPLv2
7 *
8 * The basic idea here is to enable a device to be attached to an
9 * aritrary numer of classes without having to allocate storage for them.
10 * Instead, the contained classes select the devices they need to attach
11 * to via a matching function.
12 */
13
14#include <linux/attribute_container.h>
15#include <linux/device.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/list.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21
22#include "base.h"
23
24/* This is a private structure used to tie the classdev and the
25 * container .. it should never be visible outside this file */
26struct internal_container {
27 struct klist_node node;
28 struct attribute_container *cont;
29 struct device classdev;
30};
31
32static void internal_container_klist_get(struct klist_node *n)
33{
34 struct internal_container *ic =
35 container_of(n, struct internal_container, node);
36 get_device(&ic->classdev);
37}
38
39static void internal_container_klist_put(struct klist_node *n)
40{
41 struct internal_container *ic =
42 container_of(n, struct internal_container, node);
43 put_device(&ic->classdev);
44}
45
46
47/**
48 * attribute_container_classdev_to_container - given a classdev, return the container
49 *
50 * @classdev: the class device created by attribute_container_add_device.
51 *
52 * Returns the container associated with this classdev.
53 */
54struct attribute_container *
55attribute_container_classdev_to_container(struct device *classdev)
56{
57 struct internal_container *ic =
58 container_of(classdev, struct internal_container, classdev);
59 return ic->cont;
60}
61EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container);
62
63static LIST_HEAD(attribute_container_list);
64
65static DEFINE_MUTEX(attribute_container_mutex);
66
67/**
68 * attribute_container_register - register an attribute container
69 *
70 * @cont: The container to register. This must be allocated by the
71 * callee and should also be zeroed by it.
72 */
73int
74attribute_container_register(struct attribute_container *cont)
75{
76 INIT_LIST_HEAD(&cont->node);
77 klist_init(&cont->containers,internal_container_klist_get,
78 internal_container_klist_put);
79
80 mutex_lock(&attribute_container_mutex);
81 list_add_tail(&cont->node, &attribute_container_list);
82 mutex_unlock(&attribute_container_mutex);
83
84 return 0;
85}
86EXPORT_SYMBOL_GPL(attribute_container_register);
87
88/**
89 * attribute_container_unregister - remove a container registration
90 *
91 * @cont: previously registered container to remove
92 */
93int
94attribute_container_unregister(struct attribute_container *cont)
95{
96 int retval = -EBUSY;
97 mutex_lock(&attribute_container_mutex);
98 spin_lock(&cont->containers.k_lock);
99 if (!list_empty(&cont->containers.k_list))
100 goto out;
101 retval = 0;
102 list_del(&cont->node);
103 out:
104 spin_unlock(&cont->containers.k_lock);
105 mutex_unlock(&attribute_container_mutex);
106 return retval;
107
108}
109EXPORT_SYMBOL_GPL(attribute_container_unregister);
110
111/* private function used as class release */
112static void attribute_container_release(struct device *classdev)
113{
114 struct internal_container *ic
115 = container_of(classdev, struct internal_container, classdev);
116 struct device *dev = classdev->parent;
117
118 kfree(ic);
119 put_device(dev);
120}
121
122/**
123 * attribute_container_add_device - see if any container is interested in dev
124 *
125 * @dev: device to add attributes to
126 * @fn: function to trigger addition of class device.
127 *
128 * This function allocates storage for the class device(s) to be
129 * attached to dev (one for each matching attribute_container). If no
130 * fn is provided, the code will simply register the class device via
131 * device_add. If a function is provided, it is expected to add
132 * the class device at the appropriate time. One of the things that
133 * might be necessary is to allocate and initialise the classdev and
134 * then add it a later time. To do this, call this routine for
135 * allocation and initialisation and then use
136 * attribute_container_device_trigger() to call device_add() on
137 * it. Note: after this, the class device contains a reference to dev
138 * which is not relinquished until the release of the classdev.
139 */
140void
141attribute_container_add_device(struct device *dev,
142 int (*fn)(struct attribute_container *,
143 struct device *,
144 struct device *))
145{
146 struct attribute_container *cont;
147
148 mutex_lock(&attribute_container_mutex);
149 list_for_each_entry(cont, &attribute_container_list, node) {
150 struct internal_container *ic;
151
152 if (attribute_container_no_classdevs(cont))
153 continue;
154
155 if (!cont->match(cont, dev))
156 continue;
157
158 ic = kzalloc(sizeof(*ic), GFP_KERNEL);
159 if (!ic) {
160 dev_err(dev, "failed to allocate class container\n");
161 continue;
162 }
163
164 ic->cont = cont;
165 device_initialize(&ic->classdev);
166 ic->classdev.parent = get_device(dev);
167 ic->classdev.class = cont->class;
168 cont->class->dev_release = attribute_container_release;
169 dev_set_name(&ic->classdev, "%s", dev_name(dev));
170 if (fn)
171 fn(cont, dev, &ic->classdev);
172 else
173 attribute_container_add_class_device(&ic->classdev);
174 klist_add_tail(&ic->node, &cont->containers);
175 }
176 mutex_unlock(&attribute_container_mutex);
177}
178
179/* FIXME: can't break out of this unless klist_iter_exit is also
180 * called before doing the break
181 */
182#define klist_for_each_entry(pos, head, member, iter) \
183 for (klist_iter_init(head, iter); (pos = ({ \
184 struct klist_node *n = klist_next(iter); \
185 n ? container_of(n, typeof(*pos), member) : \
186 ({ klist_iter_exit(iter) ; NULL; }); \
187 }) ) != NULL; )
188
189
190/**
191 * attribute_container_remove_device - make device eligible for removal.
192 *
193 * @dev: The generic device
194 * @fn: A function to call to remove the device
195 *
196 * This routine triggers device removal. If fn is NULL, then it is
197 * simply done via device_unregister (note that if something
198 * still has a reference to the classdev, then the memory occupied
199 * will not be freed until the classdev is released). If you want a
200 * two phase release: remove from visibility and then delete the
201 * device, then you should use this routine with a fn that calls
202 * device_del() and then use attribute_container_device_trigger()
203 * to do the final put on the classdev.
204 */
205void
206attribute_container_remove_device(struct device *dev,
207 void (*fn)(struct attribute_container *,
208 struct device *,
209 struct device *))
210{
211 struct attribute_container *cont;
212
213 mutex_lock(&attribute_container_mutex);
214 list_for_each_entry(cont, &attribute_container_list, node) {
215 struct internal_container *ic;
216 struct klist_iter iter;
217
218 if (attribute_container_no_classdevs(cont))
219 continue;
220
221 if (!cont->match(cont, dev))
222 continue;
223
224 klist_for_each_entry(ic, &cont->containers, node, &iter) {
225 if (dev != ic->classdev.parent)
226 continue;
227 klist_del(&ic->node);
228 if (fn)
229 fn(cont, dev, &ic->classdev);
230 else {
231 attribute_container_remove_attrs(&ic->classdev);
232 device_unregister(&ic->classdev);
233 }
234 }
235 }
236 mutex_unlock(&attribute_container_mutex);
237}
238
239/**
240 * attribute_container_device_trigger - execute a trigger for each matching classdev
241 *
242 * @dev: The generic device to run the trigger for
243 * @fn the function to execute for each classdev.
244 *
245 * This funcion is for executing a trigger when you need to know both
246 * the container and the classdev. If you only care about the
247 * container, then use attribute_container_trigger() instead.
248 */
249void
250attribute_container_device_trigger(struct device *dev,
251 int (*fn)(struct attribute_container *,
252 struct device *,
253 struct device *))
254{
255 struct attribute_container *cont;
256
257 mutex_lock(&attribute_container_mutex);
258 list_for_each_entry(cont, &attribute_container_list, node) {
259 struct internal_container *ic;
260 struct klist_iter iter;
261
262 if (!cont->match(cont, dev))
263 continue;
264
265 if (attribute_container_no_classdevs(cont)) {
266 fn(cont, dev, NULL);
267 continue;
268 }
269
270 klist_for_each_entry(ic, &cont->containers, node, &iter) {
271 if (dev == ic->classdev.parent)
272 fn(cont, dev, &ic->classdev);
273 }
274 }
275 mutex_unlock(&attribute_container_mutex);
276}
277
278/**
279 * attribute_container_trigger - trigger a function for each matching container
280 *
281 * @dev: The generic device to activate the trigger for
282 * @fn: the function to trigger
283 *
284 * This routine triggers a function that only needs to know the
285 * matching containers (not the classdev) associated with a device.
286 * It is more lightweight than attribute_container_device_trigger, so
287 * should be used in preference unless the triggering function
288 * actually needs to know the classdev.
289 */
290void
291attribute_container_trigger(struct device *dev,
292 int (*fn)(struct attribute_container *,
293 struct device *))
294{
295 struct attribute_container *cont;
296
297 mutex_lock(&attribute_container_mutex);
298 list_for_each_entry(cont, &attribute_container_list, node) {
299 if (cont->match(cont, dev))
300 fn(cont, dev);
301 }
302 mutex_unlock(&attribute_container_mutex);
303}
304
305/**
306 * attribute_container_add_attrs - add attributes
307 *
308 * @classdev: The class device
309 *
310 * This simply creates all the class device sysfs files from the
311 * attributes listed in the container
312 */
313int
314attribute_container_add_attrs(struct device *classdev)
315{
316 struct attribute_container *cont =
317 attribute_container_classdev_to_container(classdev);
318 struct device_attribute **attrs = cont->attrs;
319 int i, error;
320
321 BUG_ON(attrs && cont->grp);
322
323 if (!attrs && !cont->grp)
324 return 0;
325
326 if (cont->grp)
327 return sysfs_create_group(&classdev->kobj, cont->grp);
328
329 for (i = 0; attrs[i]; i++) {
330 sysfs_attr_init(&attrs[i]->attr);
331 error = device_create_file(classdev, attrs[i]);
332 if (error)
333 return error;
334 }
335
336 return 0;
337}
338
339/**
340 * attribute_container_add_class_device - same function as device_add
341 *
342 * @classdev: the class device to add
343 *
344 * This performs essentially the same function as device_add except for
345 * attribute containers, namely add the classdev to the system and then
346 * create the attribute files
347 */
348int
349attribute_container_add_class_device(struct device *classdev)
350{
351 int error = device_add(classdev);
352 if (error)
353 return error;
354 return attribute_container_add_attrs(classdev);
355}
356
357/**
358 * attribute_container_add_class_device_adapter - simple adapter for triggers
359 *
360 * This function is identical to attribute_container_add_class_device except
361 * that it is designed to be called from the triggers
362 */
363int
364attribute_container_add_class_device_adapter(struct attribute_container *cont,
365 struct device *dev,
366 struct device *classdev)
367{
368 return attribute_container_add_class_device(classdev);
369}
370
371/**
372 * attribute_container_remove_attrs - remove any attribute files
373 *
374 * @classdev: The class device to remove the files from
375 *
376 */
377void
378attribute_container_remove_attrs(struct device *classdev)
379{
380 struct attribute_container *cont =
381 attribute_container_classdev_to_container(classdev);
382 struct device_attribute **attrs = cont->attrs;
383 int i;
384
385 if (!attrs && !cont->grp)
386 return;
387
388 if (cont->grp) {
389 sysfs_remove_group(&classdev->kobj, cont->grp);
390 return ;
391 }
392
393 for (i = 0; attrs[i]; i++)
394 device_remove_file(classdev, attrs[i]);
395}
396
397/**
398 * attribute_container_class_device_del - equivalent of class_device_del
399 *
400 * @classdev: the class device
401 *
402 * This function simply removes all the attribute files and then calls
403 * device_del.
404 */
405void
406attribute_container_class_device_del(struct device *classdev)
407{
408 attribute_container_remove_attrs(classdev);
409 device_del(classdev);
410}
411
412/**
413 * attribute_container_find_class_device - find the corresponding class_device
414 *
415 * @cont: the container
416 * @dev: the generic device
417 *
418 * Looks up the device in the container's list of class devices and returns
419 * the corresponding class_device.
420 */
421struct device *
422attribute_container_find_class_device(struct attribute_container *cont,
423 struct device *dev)
424{
425 struct device *cdev = NULL;
426 struct internal_container *ic;
427 struct klist_iter iter;
428
429 klist_for_each_entry(ic, &cont->containers, node, &iter) {
430 if (ic->classdev.parent == dev) {
431 cdev = &ic->classdev;
432 /* FIXME: must exit iterator then break */
433 klist_iter_exit(&iter);
434 break;
435 }
436 }
437
438 return cdev;
439}
440EXPORT_SYMBOL_GPL(attribute_container_find_class_device);