aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-08-25 13:50:19 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:04 -0400
commit5a3ceb861663040f9ef0176df4aaa494bba5e352 (patch)
tree035472164252c3b54071f044c161b312b6bc8b44 /include/linux/device.h
parenta1ed5b0cffe4b16a93a6a3390e8cee0fbef94f86 (diff)
driver-core: use klist for class device list and implement iterator
Iterating over entries using callback usually isn't too fun especially when the entry being iterated over can't be manipulated freely. This patch converts class->p->class_devices to klist and implements class device iterator so that the users can freely build their own control structure. The users are also free to call back into class code without worrying about locking. class_for_each_device() and class_find_device() are converted to use the new iterators, so their users don't have to worry about locking anymore either. Note: This depends on klist-dont-iterate-over-deleted-entries patch because class_intf->add/remove_dev() depends on proper synchronization with device removal. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Greg Kroah-Hartman <gregkh@suse.de> Cc: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 4d8372d135df..246937c9cbc7 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -199,6 +199,11 @@ struct class {
199 struct class_private *p; 199 struct class_private *p;
200}; 200};
201 201
202struct class_dev_iter {
203 struct klist_iter ki;
204 const struct device_type *type;
205};
206
202extern struct kobject *sysfs_dev_block_kobj; 207extern struct kobject *sysfs_dev_block_kobj;
203extern struct kobject *sysfs_dev_char_kobj; 208extern struct kobject *sysfs_dev_char_kobj;
204extern int __must_check __class_register(struct class *class, 209extern int __must_check __class_register(struct class *class,
@@ -213,6 +218,13 @@ extern void class_unregister(struct class *class);
213 __class_register(class, &__key); \ 218 __class_register(class, &__key); \
214}) 219})
215 220
221extern void class_dev_iter_init(struct class_dev_iter *iter,
222 struct class *class,
223 struct device *start,
224 const struct device_type *type);
225extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
226extern void class_dev_iter_exit(struct class_dev_iter *iter);
227
216extern int class_for_each_device(struct class *class, struct device *start, 228extern int class_for_each_device(struct class *class, struct device *start,
217 void *data, 229 void *data,
218 int (*fn)(struct device *dev, void *data)); 230 int (*fn)(struct device *dev, void *data));
@@ -396,7 +408,7 @@ struct device {
396 spinlock_t devres_lock; 408 spinlock_t devres_lock;
397 struct list_head devres_head; 409 struct list_head devres_head;
398 410
399 struct list_head node; 411 struct klist_node knode_class;
400 struct class *class; 412 struct class *class;
401 dev_t devt; /* dev_t, creates the sysfs "dev" */ 413 dev_t devt; /* dev_t, creates the sysfs "dev" */
402 struct attribute_group **groups; /* optional groups */ 414 struct attribute_group **groups; /* optional groups */