diff options
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r-- | drivers/base/core.c | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 61df508fa62b..8079afca4972 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -109,7 +109,6 @@ static struct sysfs_ops dev_sysfs_ops = { | |||
109 | static void device_release(struct kobject *kobj) | 109 | static void device_release(struct kobject *kobj) |
110 | { | 110 | { |
111 | struct device *dev = to_dev(kobj); | 111 | struct device *dev = to_dev(kobj); |
112 | struct device_private *p = dev->p; | ||
113 | 112 | ||
114 | if (dev->release) | 113 | if (dev->release) |
115 | dev->release(dev); | 114 | dev->release(dev); |
@@ -121,7 +120,6 @@ static void device_release(struct kobject *kobj) | |||
121 | WARN(1, KERN_ERR "Device '%s' does not have a release() " | 120 | WARN(1, KERN_ERR "Device '%s' does not have a release() " |
122 | "function, it is broken and must be fixed.\n", | 121 | "function, it is broken and must be fixed.\n", |
123 | dev_name(dev)); | 122 | dev_name(dev)); |
124 | kfree(p); | ||
125 | } | 123 | } |
126 | 124 | ||
127 | static struct kobj_type device_ktype = { | 125 | static struct kobj_type device_ktype = { |
@@ -509,16 +507,14 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner); | |||
509 | 507 | ||
510 | static void klist_children_get(struct klist_node *n) | 508 | static void klist_children_get(struct klist_node *n) |
511 | { | 509 | { |
512 | struct device_private *p = to_device_private_parent(n); | 510 | struct device *dev = container_of(n, struct device, knode_parent); |
513 | struct device *dev = p->device; | ||
514 | 511 | ||
515 | get_device(dev); | 512 | get_device(dev); |
516 | } | 513 | } |
517 | 514 | ||
518 | static void klist_children_put(struct klist_node *n) | 515 | static void klist_children_put(struct klist_node *n) |
519 | { | 516 | { |
520 | struct device_private *p = to_device_private_parent(n); | 517 | struct device *dev = container_of(n, struct device, knode_parent); |
521 | struct device *dev = p->device; | ||
522 | 518 | ||
523 | put_device(dev); | 519 | put_device(dev); |
524 | } | 520 | } |
@@ -540,15 +536,9 @@ static void klist_children_put(struct klist_node *n) | |||
540 | */ | 536 | */ |
541 | void device_initialize(struct device *dev) | 537 | void device_initialize(struct device *dev) |
542 | { | 538 | { |
543 | dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL); | ||
544 | if (!dev->p) { | ||
545 | WARN_ON(1); | ||
546 | return; | ||
547 | } | ||
548 | dev->p->device = dev; | ||
549 | dev->kobj.kset = devices_kset; | 539 | dev->kobj.kset = devices_kset; |
550 | kobject_init(&dev->kobj, &device_ktype); | 540 | kobject_init(&dev->kobj, &device_ktype); |
551 | klist_init(&dev->p->klist_children, klist_children_get, | 541 | klist_init(&dev->klist_children, klist_children_get, |
552 | klist_children_put); | 542 | klist_children_put); |
553 | INIT_LIST_HEAD(&dev->dma_pools); | 543 | INIT_LIST_HEAD(&dev->dma_pools); |
554 | init_MUTEX(&dev->sem); | 544 | init_MUTEX(&dev->sem); |
@@ -932,8 +922,7 @@ int device_add(struct device *dev) | |||
932 | kobject_uevent(&dev->kobj, KOBJ_ADD); | 922 | kobject_uevent(&dev->kobj, KOBJ_ADD); |
933 | bus_attach_device(dev); | 923 | bus_attach_device(dev); |
934 | if (parent) | 924 | if (parent) |
935 | klist_add_tail(&dev->p->knode_parent, | 925 | klist_add_tail(&dev->knode_parent, &parent->klist_children); |
936 | &parent->p->klist_children); | ||
937 | 926 | ||
938 | if (dev->class) { | 927 | if (dev->class) { |
939 | mutex_lock(&dev->class->p->class_mutex); | 928 | mutex_lock(&dev->class->p->class_mutex); |
@@ -1047,7 +1036,7 @@ void device_del(struct device *dev) | |||
1047 | device_pm_remove(dev); | 1036 | device_pm_remove(dev); |
1048 | dpm_sysfs_remove(dev); | 1037 | dpm_sysfs_remove(dev); |
1049 | if (parent) | 1038 | if (parent) |
1050 | klist_del(&dev->p->knode_parent); | 1039 | klist_del(&dev->knode_parent); |
1051 | if (MAJOR(dev->devt)) { | 1040 | if (MAJOR(dev->devt)) { |
1052 | device_remove_sys_dev_entry(dev); | 1041 | device_remove_sys_dev_entry(dev); |
1053 | device_remove_file(dev, &devt_attr); | 1042 | device_remove_file(dev, &devt_attr); |
@@ -1108,14 +1097,7 @@ void device_unregister(struct device *dev) | |||
1108 | static struct device *next_device(struct klist_iter *i) | 1097 | static struct device *next_device(struct klist_iter *i) |
1109 | { | 1098 | { |
1110 | struct klist_node *n = klist_next(i); | 1099 | struct klist_node *n = klist_next(i); |
1111 | struct device *dev = NULL; | 1100 | return n ? container_of(n, struct device, knode_parent) : NULL; |
1112 | struct device_private *p; | ||
1113 | |||
1114 | if (n) { | ||
1115 | p = to_device_private_parent(n); | ||
1116 | dev = p->device; | ||
1117 | } | ||
1118 | return dev; | ||
1119 | } | 1101 | } |
1120 | 1102 | ||
1121 | /** | 1103 | /** |
@@ -1137,7 +1119,7 @@ int device_for_each_child(struct device *parent, void *data, | |||
1137 | struct device *child; | 1119 | struct device *child; |
1138 | int error = 0; | 1120 | int error = 0; |
1139 | 1121 | ||
1140 | klist_iter_init(&parent->p->klist_children, &i); | 1122 | klist_iter_init(&parent->klist_children, &i); |
1141 | while ((child = next_device(&i)) && !error) | 1123 | while ((child = next_device(&i)) && !error) |
1142 | error = fn(child, data); | 1124 | error = fn(child, data); |
1143 | klist_iter_exit(&i); | 1125 | klist_iter_exit(&i); |
@@ -1168,7 +1150,7 @@ struct device *device_find_child(struct device *parent, void *data, | |||
1168 | if (!parent) | 1150 | if (!parent) |
1169 | return NULL; | 1151 | return NULL; |
1170 | 1152 | ||
1171 | klist_iter_init(&parent->p->klist_children, &i); | 1153 | klist_iter_init(&parent->klist_children, &i); |
1172 | while ((child = next_device(&i))) | 1154 | while ((child = next_device(&i))) |
1173 | if (match(child, data) && get_device(child)) | 1155 | if (match(child, data) && get_device(child)) |
1174 | break; | 1156 | break; |
@@ -1582,10 +1564,9 @@ int device_move(struct device *dev, struct device *new_parent) | |||
1582 | old_parent = dev->parent; | 1564 | old_parent = dev->parent; |
1583 | dev->parent = new_parent; | 1565 | dev->parent = new_parent; |
1584 | if (old_parent) | 1566 | if (old_parent) |
1585 | klist_remove(&dev->p->knode_parent); | 1567 | klist_remove(&dev->knode_parent); |
1586 | if (new_parent) { | 1568 | if (new_parent) { |
1587 | klist_add_tail(&dev->p->knode_parent, | 1569 | klist_add_tail(&dev->knode_parent, &new_parent->klist_children); |
1588 | &new_parent->p->klist_children); | ||
1589 | set_dev_node(dev, dev_to_node(new_parent)); | 1570 | set_dev_node(dev, dev_to_node(new_parent)); |
1590 | } | 1571 | } |
1591 | 1572 | ||
@@ -1597,11 +1578,11 @@ int device_move(struct device *dev, struct device *new_parent) | |||
1597 | device_move_class_links(dev, new_parent, old_parent); | 1578 | device_move_class_links(dev, new_parent, old_parent); |
1598 | if (!kobject_move(&dev->kobj, &old_parent->kobj)) { | 1579 | if (!kobject_move(&dev->kobj, &old_parent->kobj)) { |
1599 | if (new_parent) | 1580 | if (new_parent) |
1600 | klist_remove(&dev->p->knode_parent); | 1581 | klist_remove(&dev->knode_parent); |
1601 | dev->parent = old_parent; | 1582 | dev->parent = old_parent; |
1602 | if (old_parent) { | 1583 | if (old_parent) { |
1603 | klist_add_tail(&dev->p->knode_parent, | 1584 | klist_add_tail(&dev->knode_parent, |
1604 | &old_parent->p->klist_children); | 1585 | &old_parent->klist_children); |
1605 | set_dev_node(dev, dev_to_node(old_parent)); | 1586 | set_dev_node(dev, dev_to_node(old_parent)); |
1606 | } | 1587 | } |
1607 | } | 1588 | } |