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-03-24 19:38:25 -0400
commitf791b8c836307b58cbf62133a6a772ed1a92fb33 (patch)
treedb4e3eb6c7f90e43f4aa73009a14e285014b349a /drivers/base
parentfb069a5d132fb926ed17af3211a114ac7cf27d7a (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.c39
2 files changed, 31 insertions, 14 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 62a2cb5e1780..7c4fafc314c4 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 16d859910104..a90f56f64d6f 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}
@@ -540,8 +542,6 @@ void device_initialize(struct device *dev)
540{ 542{
541 dev->kobj.kset = devices_kset; 543 dev->kobj.kset = devices_kset;
542 kobject_init(&dev->kobj, &device_ktype); 544 kobject_init(&dev->kobj, &device_ktype);
543 klist_init(&dev->klist_children, klist_children_get,
544 klist_children_put);
545 INIT_LIST_HEAD(&dev->dma_pools); 545 INIT_LIST_HEAD(&dev->dma_pools);
546 init_MUTEX(&dev->sem); 546 init_MUTEX(&dev->sem);
547 spin_lock_init(&dev->devres_lock); 547 spin_lock_init(&dev->devres_lock);
@@ -867,6 +867,8 @@ int device_add(struct device *dev)
867 goto done; 867 goto done;
868 } 868 }
869 dev->p->device = dev; 869 dev->p->device = dev;
870 klist_init(&dev->p->klist_children, klist_children_get,
871 klist_children_put);
870 872
871 /* 873 /*
872 * for statically allocated devices, which should all be converted 874 * for statically allocated devices, which should all be converted
@@ -937,7 +939,8 @@ int device_add(struct device *dev)
937 kobject_uevent(&dev->kobj, KOBJ_ADD); 939 kobject_uevent(&dev->kobj, KOBJ_ADD);
938 bus_attach_device(dev); 940 bus_attach_device(dev);
939 if (parent) 941 if (parent)
940 klist_add_tail(&dev->knode_parent, &parent->klist_children); 942 klist_add_tail(&dev->p->knode_parent,
943 &parent->p->klist_children);
941 944
942 if (dev->class) { 945 if (dev->class) {
943 mutex_lock(&dev->class->p->class_mutex); 946 mutex_lock(&dev->class->p->class_mutex);
@@ -1051,7 +1054,7 @@ void device_del(struct device *dev)
1051 device_pm_remove(dev); 1054 device_pm_remove(dev);
1052 dpm_sysfs_remove(dev); 1055 dpm_sysfs_remove(dev);
1053 if (parent) 1056 if (parent)
1054 klist_del(&dev->knode_parent); 1057 klist_del(&dev->p->knode_parent);
1055 if (MAJOR(dev->devt)) { 1058 if (MAJOR(dev->devt)) {
1056 device_remove_sys_dev_entry(dev); 1059 device_remove_sys_dev_entry(dev);
1057 device_remove_file(dev, &devt_attr); 1060 device_remove_file(dev, &devt_attr);
@@ -1112,7 +1115,14 @@ void device_unregister(struct device *dev)
1112static struct device *next_device(struct klist_iter *i) 1115static struct device *next_device(struct klist_iter *i)
1113{ 1116{
1114 struct klist_node *n = klist_next(i); 1117 struct klist_node *n = klist_next(i);
1115 return n ? container_of(n, struct device, knode_parent) : NULL; 1118 struct device *dev = NULL;
1119 struct device_private *p;
1120
1121 if (n) {
1122 p = to_device_private_parent(n);
1123 dev = p->device;
1124 }
1125 return dev;
1116} 1126}
1117 1127
1118/** 1128/**
@@ -1134,7 +1144,7 @@ int device_for_each_child(struct device *parent, void *data,
1134 struct device *child; 1144 struct device *child;
1135 int error = 0; 1145 int error = 0;
1136 1146
1137 klist_iter_init(&parent->klist_children, &i); 1147 klist_iter_init(&parent->p->klist_children, &i);
1138 while ((child = next_device(&i)) && !error) 1148 while ((child = next_device(&i)) && !error)
1139 error = fn(child, data); 1149 error = fn(child, data);
1140 klist_iter_exit(&i); 1150 klist_iter_exit(&i);
@@ -1165,7 +1175,7 @@ struct device *device_find_child(struct device *parent, void *data,
1165 if (!parent) 1175 if (!parent)
1166 return NULL; 1176 return NULL;
1167 1177
1168 klist_iter_init(&parent->klist_children, &i); 1178 klist_iter_init(&parent->p->klist_children, &i);
1169 while ((child = next_device(&i))) 1179 while ((child = next_device(&i)))
1170 if (match(child, data) && get_device(child)) 1180 if (match(child, data) && get_device(child))
1171 break; 1181 break;
@@ -1578,9 +1588,10 @@ int device_move(struct device *dev, struct device *new_parent)
1578 old_parent = dev->parent; 1588 old_parent = dev->parent;
1579 dev->parent = new_parent; 1589 dev->parent = new_parent;
1580 if (old_parent) 1590 if (old_parent)
1581 klist_remove(&dev->knode_parent); 1591 klist_remove(&dev->p->knode_parent);
1582 if (new_parent) { 1592 if (new_parent) {
1583 klist_add_tail(&dev->knode_parent, &new_parent->klist_children); 1593 klist_add_tail(&dev->p->knode_parent,
1594 &new_parent->p->klist_children);
1584 set_dev_node(dev, dev_to_node(new_parent)); 1595 set_dev_node(dev, dev_to_node(new_parent));
1585 } 1596 }
1586 1597
@@ -1592,11 +1603,11 @@ int device_move(struct device *dev, struct device *new_parent)
1592 device_move_class_links(dev, new_parent, old_parent); 1603 device_move_class_links(dev, new_parent, old_parent);
1593 if (!kobject_move(&dev->kobj, &old_parent->kobj)) { 1604 if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
1594 if (new_parent) 1605 if (new_parent)
1595 klist_remove(&dev->knode_parent); 1606 klist_remove(&dev->p->knode_parent);
1596 dev->parent = old_parent; 1607 dev->parent = old_parent;
1597 if (old_parent) { 1608 if (old_parent) {
1598 klist_add_tail(&dev->knode_parent, 1609 klist_add_tail(&dev->p->knode_parent,
1599 &old_parent->klist_children); 1610 &old_parent->p->klist_children);
1600 set_dev_node(dev, dev_to_node(old_parent)); 1611 set_dev_node(dev, dev_to_node(old_parent));
1601 } 1612 }
1602 } 1613 }