aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2008-12-16 15:24:56 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-01-06 13:44:32 -0500
commit11c3b5c3e08f4d855cbef52883c266b9ab9df879 (patch)
tree43278db9cb198f3800eaa73c3c051d875c92709d /drivers/base
parent2831fe6f9cc4e16c103504ee09a47a084297c0f3 (diff)
driver core: move klist_children into private structure
Nothing outside of the driver core should ever touch klist_children, or knode_parent, so move them out of the public eye. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/base.h6
-rw-r--r--drivers/base/core.c37
2 files changed, 30 insertions, 13 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 6b20809b5fd4..f5cf31c664d7 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -66,14 +66,20 @@ struct class_private {
66/** 66/**
67 * struct device_private - structure to hold the private to the driver core portions of the device structure. 67 * struct device_private - structure to hold the private to the driver core portions of the device structure.
68 * 68 *
69 * @klist_children - klist containing all children of this device
70 * @knode_parent - node in sibling list
69 * @device - pointer back to the struct class that this structure is 71 * @device - pointer back to the struct class that this structure is
70 * associated with. 72 * associated with.
71 * 73 *
72 * Nothing outside of the driver core should ever touch these fields. 74 * Nothing outside of the driver core should ever touch these fields.
73 */ 75 */
74struct device_private { 76struct device_private {
77 struct klist klist_children;
78 struct klist_node knode_parent;
75 struct device *device; 79 struct device *device;
76}; 80};
81#define to_device_private_parent(obj) \
82 container_of(obj, struct device_private, knode_parent)
77 83
78/* initialisation functions */ 84/* initialisation functions */
79extern int devices_init(void); 85extern int devices_init(void);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6657787e64f8..180ff84ea26c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -509,14 +509,16 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
509 509
510static void klist_children_get(struct klist_node *n) 510static void klist_children_get(struct klist_node *n)
511{ 511{
512 struct device *dev = container_of(n, struct device, knode_parent); 512 struct device_private *p = to_device_private_parent(n);
513 struct device *dev = p->device;
513 514
514 get_device(dev); 515 get_device(dev);
515} 516}
516 517
517static void klist_children_put(struct klist_node *n) 518static void klist_children_put(struct klist_node *n)
518{ 519{
519 struct device *dev = container_of(n, struct device, knode_parent); 520 struct device_private *p = to_device_private_parent(n);
521 struct device *dev = p->device;
520 522
521 put_device(dev); 523 put_device(dev);
522} 524}
@@ -546,7 +548,7 @@ void device_initialize(struct device *dev)
546 dev->p->device = dev; 548 dev->p->device = dev;
547 dev->kobj.kset = devices_kset; 549 dev->kobj.kset = devices_kset;
548 kobject_init(&dev->kobj, &device_ktype); 550 kobject_init(&dev->kobj, &device_ktype);
549 klist_init(&dev->klist_children, klist_children_get, 551 klist_init(&dev->p->klist_children, klist_children_get,
550 klist_children_put); 552 klist_children_put);
551 INIT_LIST_HEAD(&dev->dma_pools); 553 INIT_LIST_HEAD(&dev->dma_pools);
552 init_MUTEX(&dev->sem); 554 init_MUTEX(&dev->sem);
@@ -927,7 +929,8 @@ int device_add(struct device *dev)
927 kobject_uevent(&dev->kobj, KOBJ_ADD); 929 kobject_uevent(&dev->kobj, KOBJ_ADD);
928 bus_attach_device(dev); 930 bus_attach_device(dev);
929 if (parent) 931 if (parent)
930 klist_add_tail(&dev->knode_parent, &parent->klist_children); 932 klist_add_tail(&dev->p->knode_parent,
933 &parent->p->klist_children);
931 934
932 if (dev->class) { 935 if (dev->class) {
933 mutex_lock(&dev->class->p->class_mutex); 936 mutex_lock(&dev->class->p->class_mutex);
@@ -1038,7 +1041,7 @@ void device_del(struct device *dev)
1038 device_pm_remove(dev); 1041 device_pm_remove(dev);
1039 dpm_sysfs_remove(dev); 1042 dpm_sysfs_remove(dev);
1040 if (parent) 1043 if (parent)
1041 klist_del(&dev->knode_parent); 1044 klist_del(&dev->p->knode_parent);
1042 if (MAJOR(dev->devt)) { 1045 if (MAJOR(dev->devt)) {
1043 device_remove_sys_dev_entry(dev); 1046 device_remove_sys_dev_entry(dev);
1044 device_remove_file(dev, &devt_attr); 1047 device_remove_file(dev, &devt_attr);
@@ -1102,7 +1105,14 @@ void device_unregister(struct device *dev)
1102static struct device *next_device(struct klist_iter *i) 1105static struct device *next_device(struct klist_iter *i)
1103{ 1106{
1104 struct klist_node *n = klist_next(i); 1107 struct klist_node *n = klist_next(i);
1105 return n ? container_of(n, struct device, knode_parent) : NULL; 1108 struct device *dev = NULL;
1109 struct device_private *p;
1110
1111 if (n) {
1112 p = to_device_private_parent(n);
1113 dev = p->device;
1114 }
1115 return dev;
1106} 1116}
1107 1117
1108/** 1118/**
@@ -1124,7 +1134,7 @@ int device_for_each_child(struct device *parent, void *data,
1124 struct device *child; 1134 struct device *child;
1125 int error = 0; 1135 int error = 0;
1126 1136
1127 klist_iter_init(&parent->klist_children, &i); 1137 klist_iter_init(&parent->p->klist_children, &i);
1128 while ((child = next_device(&i)) && !error) 1138 while ((child = next_device(&i)) && !error)
1129 error = fn(child, data); 1139 error = fn(child, data);
1130 klist_iter_exit(&i); 1140 klist_iter_exit(&i);
@@ -1155,7 +1165,7 @@ struct device *device_find_child(struct device *parent, void *data,
1155 if (!parent) 1165 if (!parent)
1156 return NULL; 1166 return NULL;
1157 1167
1158 klist_iter_init(&parent->klist_children, &i); 1168 klist_iter_init(&parent->p->klist_children, &i);
1159 while ((child = next_device(&i))) 1169 while ((child = next_device(&i)))
1160 if (match(child, data) && get_device(child)) 1170 if (match(child, data) && get_device(child))
1161 break; 1171 break;
@@ -1478,9 +1488,10 @@ int device_move(struct device *dev, struct device *new_parent)
1478 old_parent = dev->parent; 1488 old_parent = dev->parent;
1479 dev->parent = new_parent; 1489 dev->parent = new_parent;
1480 if (old_parent) 1490 if (old_parent)
1481 klist_remove(&dev->knode_parent); 1491 klist_remove(&dev->p->knode_parent);
1482 if (new_parent) { 1492 if (new_parent) {
1483 klist_add_tail(&dev->knode_parent, &new_parent->klist_children); 1493 klist_add_tail(&dev->p->knode_parent,
1494 &new_parent->p->klist_children);
1484 set_dev_node(dev, dev_to_node(new_parent)); 1495 set_dev_node(dev, dev_to_node(new_parent));
1485 } 1496 }
1486 1497
@@ -1492,11 +1503,11 @@ int device_move(struct device *dev, struct device *new_parent)
1492 device_move_class_links(dev, new_parent, old_parent); 1503 device_move_class_links(dev, new_parent, old_parent);
1493 if (!kobject_move(&dev->kobj, &old_parent->kobj)) { 1504 if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
1494 if (new_parent) 1505 if (new_parent)
1495 klist_remove(&dev->knode_parent); 1506 klist_remove(&dev->p->knode_parent);
1496 dev->parent = old_parent; 1507 dev->parent = old_parent;
1497 if (old_parent) { 1508 if (old_parent) {
1498 klist_add_tail(&dev->knode_parent, 1509 klist_add_tail(&dev->p->knode_parent,
1499 &old_parent->klist_children); 1510 &old_parent->p->klist_children);
1500 set_dev_node(dev, dev_to_node(old_parent)); 1511 set_dev_node(dev, dev_to_node(old_parent));
1501 } 1512 }
1502 } 1513 }