From 4db8e282f2d1dfa43d51ce2a4817901312c9134d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 9 Jan 2009 14:32:46 -0800 Subject: Revert "driver core: move knode_bus into private structure" This reverts commit b9daa99ee533578e3f88231e7a16784dcb44ec42. Turns out that device_initialize shouldn't fail silently. This series needs to be reworked in order to get into proper shape. Reported-by: Stefan Richter Cc: Alan Cox Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 4 ---- drivers/base/bus.c | 40 +++++++++++++--------------------------- include/linux/device.h | 1 + 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index b676f8f801f8..8af0bb2c0aa8 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -69,7 +69,6 @@ struct class_private { * @klist_children - klist containing all children of this device * @knode_parent - node in sibling list * @knode_driver - node in driver list - * @knode_bus - node in bus list * @device - pointer back to the struct class that this structure is * associated with. * @@ -79,15 +78,12 @@ struct device_private { struct klist klist_children; struct klist_node knode_parent; struct klist_node knode_driver; - struct klist_node knode_bus; struct device *device; }; #define to_device_private_parent(obj) \ container_of(obj, struct device_private, knode_parent) #define to_device_private_driver(obj) \ container_of(obj, struct device_private, knode_driver) -#define to_device_private_bus(obj) \ - container_of(obj, struct device_private, knode_bus) /* initialisation functions */ extern int devices_init(void); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 0f0a50444672..83f32b891fa9 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -253,14 +253,7 @@ static ssize_t store_drivers_probe(struct bus_type *bus, static struct device *next_device(struct klist_iter *i) { struct klist_node *n = klist_next(i); - struct device *dev = NULL; - struct device_private *dev_prv; - - if (n) { - dev_prv = to_device_private_bus(n); - dev = dev_prv->device; - } - return dev; + return n ? container_of(n, struct device, knode_bus) : NULL; } /** @@ -293,7 +286,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, return -EINVAL; klist_iter_init_node(&bus->p->klist_devices, &i, - (start ? &start->p->knode_bus : NULL)); + (start ? &start->knode_bus : NULL)); while ((dev = next_device(&i)) && !error) error = fn(dev, data); klist_iter_exit(&i); @@ -327,7 +320,7 @@ struct device *bus_find_device(struct bus_type *bus, return NULL; klist_iter_init_node(&bus->p->klist_devices, &i, - (start ? &start->p->knode_bus : NULL)); + (start ? &start->knode_bus : NULL)); while ((dev = next_device(&i))) if (match(dev, data) && get_device(dev)) break; @@ -514,8 +507,7 @@ void bus_attach_device(struct device *dev) ret = device_attach(dev); WARN_ON(ret < 0); if (ret >= 0) - klist_add_tail(&dev->p->knode_bus, - &bus->p->klist_devices); + klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); } } @@ -536,8 +528,8 @@ void bus_remove_device(struct device *dev) sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev_name(dev)); device_remove_attrs(dev->bus, dev); - if (klist_node_attached(&dev->p->knode_bus)) - klist_del(&dev->p->knode_bus); + if (klist_node_attached(&dev->knode_bus)) + klist_del(&dev->knode_bus); pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev_name(dev)); @@ -839,16 +831,14 @@ static void bus_remove_attrs(struct bus_type *bus) static void klist_devices_get(struct klist_node *n) { - struct device_private *dev_prv = to_device_private_bus(n); - struct device *dev = dev_prv->device; + struct device *dev = container_of(n, struct device, knode_bus); get_device(dev); } static void klist_devices_put(struct klist_node *n) { - struct device_private *dev_prv = to_device_private_bus(n); - struct device *dev = dev_prv->device; + struct device *dev = container_of(n, struct device, knode_bus); put_device(dev); } @@ -1003,20 +993,18 @@ static void device_insertion_sort_klist(struct device *a, struct list_head *list { struct list_head *pos; struct klist_node *n; - struct device_private *dev_prv; struct device *b; list_for_each(pos, list) { n = container_of(pos, struct klist_node, n_node); - dev_prv = to_device_private_bus(n); - b = dev_prv->device; + b = container_of(n, struct device, knode_bus); if (compare(a, b) <= 0) { - list_move_tail(&a->p->knode_bus.n_node, - &b->p->knode_bus.n_node); + list_move_tail(&a->knode_bus.n_node, + &b->knode_bus.n_node); return; } } - list_move_tail(&a->p->knode_bus.n_node, list); + list_move_tail(&a->knode_bus.n_node, list); } void bus_sort_breadthfirst(struct bus_type *bus, @@ -1026,7 +1014,6 @@ void bus_sort_breadthfirst(struct bus_type *bus, LIST_HEAD(sorted_devices); struct list_head *pos, *tmp; struct klist_node *n; - struct device_private *dev_prv; struct device *dev; struct klist *device_klist; @@ -1035,8 +1022,7 @@ void bus_sort_breadthfirst(struct bus_type *bus, spin_lock(&device_klist->k_lock); list_for_each_safe(pos, tmp, &device_klist->k_list) { n = container_of(pos, struct klist_node, n_node); - dev_prv = to_device_private_bus(n); - dev = dev_prv->device; + dev = container_of(n, struct device, knode_bus); device_insertion_sort_klist(dev, &sorted_devices, compare); } list_splice(&sorted_devices, &device_klist->k_list); diff --git a/include/linux/device.h b/include/linux/device.h index 7d9da4b4993f..8987f4776064 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -366,6 +366,7 @@ struct device_dma_parameters { }; struct device { + struct klist_node knode_bus; struct device *parent; struct device_private *p; -- cgit v1.2.3 From cda5e83fdea476dce9c0a9b1152cd6ca46832cc4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 9 Jan 2009 14:44:18 -0800 Subject: Revert "driver core: move knode_driver into private structure" This reverts commit 93e746db183b3bdbbda67900f79b5835f9cb388f. Turns out that device_initialize shouldn't fail silently. This series needs to be reworked in order to get into proper shape. Reported-by: Stefan Richter Cc: Alan Cox Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 4 ---- drivers/base/dd.c | 13 +++++-------- drivers/base/driver.c | 13 +++---------- include/linux/device.h | 1 + 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 8af0bb2c0aa8..f5cf31c664d7 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -68,7 +68,6 @@ struct class_private { * * @klist_children - klist containing all children of this device * @knode_parent - node in sibling list - * @knode_driver - node in driver list * @device - pointer back to the struct class that this structure is * associated with. * @@ -77,13 +76,10 @@ struct class_private { struct device_private { struct klist klist_children; struct klist_node knode_parent; - struct klist_node knode_driver; struct device *device; }; #define to_device_private_parent(obj) \ container_of(obj, struct device_private, knode_parent) -#define to_device_private_driver(obj) \ - container_of(obj, struct device_private, knode_driver) /* initialisation functions */ extern int devices_init(void); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 6fdaf76f033f..315bed8d5e7f 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -28,7 +28,7 @@ static void driver_bound(struct device *dev) { - if (klist_node_attached(&dev->p->knode_driver)) { + if (klist_node_attached(&dev->knode_driver)) { printk(KERN_WARNING "%s: device %s already bound\n", __func__, kobject_name(&dev->kobj)); return; @@ -41,7 +41,7 @@ static void driver_bound(struct device *dev) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_BOUND_DRIVER, dev); - klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); + klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices); } static int driver_sysfs_add(struct device *dev) @@ -310,7 +310,7 @@ static void __device_release_driver(struct device *dev) drv->remove(dev); devres_release_all(dev); dev->driver = NULL; - klist_remove(&dev->p->knode_driver); + klist_remove(&dev->knode_driver); } } @@ -340,7 +340,6 @@ EXPORT_SYMBOL_GPL(device_release_driver); */ void driver_detach(struct device_driver *drv) { - struct device_private *dev_prv; struct device *dev; for (;;) { @@ -349,10 +348,8 @@ void driver_detach(struct device_driver *drv) spin_unlock(&drv->p->klist_devices.k_lock); break; } - dev_prv = list_entry(drv->p->klist_devices.k_list.prev, - struct device_private, - knode_driver.n_node); - dev = dev_prv->device; + dev = list_entry(drv->p->klist_devices.k_list.prev, + struct device, knode_driver.n_node); get_device(dev); spin_unlock(&drv->p->klist_devices.k_lock); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index b76cc69f1106..1e2bda780e48 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -19,14 +19,7 @@ static struct device *next_device(struct klist_iter *i) { struct klist_node *n = klist_next(i); - struct device *dev = NULL; - struct device_private *dev_prv; - - if (n) { - dev_prv = to_device_private_driver(n); - dev = dev_prv->device; - } - return dev; + return n ? container_of(n, struct device, knode_driver) : NULL; } /** @@ -49,7 +42,7 @@ int driver_for_each_device(struct device_driver *drv, struct device *start, return -EINVAL; klist_iter_init_node(&drv->p->klist_devices, &i, - start ? &start->p->knode_driver : NULL); + start ? &start->knode_driver : NULL); while ((dev = next_device(&i)) && !error) error = fn(dev, data); klist_iter_exit(&i); @@ -83,7 +76,7 @@ struct device *driver_find_device(struct device_driver *drv, return NULL; klist_iter_init_node(&drv->p->klist_devices, &i, - (start ? &start->p->knode_driver : NULL)); + (start ? &start->knode_driver : NULL)); while ((dev = next_device(&i))) if (match(dev, data) && get_device(dev)) break; diff --git a/include/linux/device.h b/include/linux/device.h index 8987f4776064..c66ceb15acd8 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -366,6 +366,7 @@ struct device_dma_parameters { }; struct device { + struct klist_node knode_driver; struct klist_node knode_bus; struct device *parent; -- cgit v1.2.3 From e2d4077678c7ec7661003c268120582adc544897 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 9 Jan 2009 14:55:37 -0800 Subject: Revert "driver core: move klist_children into private structure" This reverts commit 11c3b5c3e08f4d855cbef52883c266b9ab9df879. Turns out that device_initialize shouldn't fail silently. This series needs to be reworked in order to get into proper shape. Reported-by: Stefan Richter Cc: Alan Cox Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 6 ------ drivers/base/core.c | 37 +++++++++++++------------------------ include/linux/device.h | 2 ++ 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index f5cf31c664d7..6b20809b5fd4 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -66,20 +66,14 @@ struct class_private { /** * struct device_private - structure to hold the private to the driver core portions of the device structure. * - * @klist_children - klist containing all children of this device - * @knode_parent - node in sibling list * @device - pointer back to the struct class that this structure is * associated with. * * Nothing outside of the driver core should ever touch these fields. */ struct device_private { - struct klist klist_children; - struct klist_node knode_parent; struct device *device; }; -#define to_device_private_parent(obj) \ - container_of(obj, struct device_private, knode_parent) /* initialisation functions */ extern int devices_init(void); diff --git a/drivers/base/core.c b/drivers/base/core.c index 61df508fa62b..5c2acf7116d7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -509,16 +509,14 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner); static void klist_children_get(struct klist_node *n) { - struct device_private *p = to_device_private_parent(n); - struct device *dev = p->device; + struct device *dev = container_of(n, struct device, knode_parent); get_device(dev); } static void klist_children_put(struct klist_node *n) { - struct device_private *p = to_device_private_parent(n); - struct device *dev = p->device; + struct device *dev = container_of(n, struct device, knode_parent); put_device(dev); } @@ -548,7 +546,7 @@ void device_initialize(struct device *dev) dev->p->device = dev; dev->kobj.kset = devices_kset; kobject_init(&dev->kobj, &device_ktype); - klist_init(&dev->p->klist_children, klist_children_get, + klist_init(&dev->klist_children, klist_children_get, klist_children_put); INIT_LIST_HEAD(&dev->dma_pools); init_MUTEX(&dev->sem); @@ -932,8 +930,7 @@ int device_add(struct device *dev) kobject_uevent(&dev->kobj, KOBJ_ADD); bus_attach_device(dev); if (parent) - klist_add_tail(&dev->p->knode_parent, - &parent->p->klist_children); + klist_add_tail(&dev->knode_parent, &parent->klist_children); if (dev->class) { mutex_lock(&dev->class->p->class_mutex); @@ -1047,7 +1044,7 @@ void device_del(struct device *dev) device_pm_remove(dev); dpm_sysfs_remove(dev); if (parent) - klist_del(&dev->p->knode_parent); + klist_del(&dev->knode_parent); if (MAJOR(dev->devt)) { device_remove_sys_dev_entry(dev); device_remove_file(dev, &devt_attr); @@ -1108,14 +1105,7 @@ void device_unregister(struct device *dev) static struct device *next_device(struct klist_iter *i) { struct klist_node *n = klist_next(i); - struct device *dev = NULL; - struct device_private *p; - - if (n) { - p = to_device_private_parent(n); - dev = p->device; - } - return dev; + return n ? container_of(n, struct device, knode_parent) : NULL; } /** @@ -1137,7 +1127,7 @@ int device_for_each_child(struct device *parent, void *data, struct device *child; int error = 0; - klist_iter_init(&parent->p->klist_children, &i); + klist_iter_init(&parent->klist_children, &i); while ((child = next_device(&i)) && !error) error = fn(child, data); klist_iter_exit(&i); @@ -1168,7 +1158,7 @@ struct device *device_find_child(struct device *parent, void *data, if (!parent) return NULL; - klist_iter_init(&parent->p->klist_children, &i); + klist_iter_init(&parent->klist_children, &i); while ((child = next_device(&i))) if (match(child, data) && get_device(child)) break; @@ -1582,10 +1572,9 @@ int device_move(struct device *dev, struct device *new_parent) old_parent = dev->parent; dev->parent = new_parent; if (old_parent) - klist_remove(&dev->p->knode_parent); + klist_remove(&dev->knode_parent); if (new_parent) { - klist_add_tail(&dev->p->knode_parent, - &new_parent->p->klist_children); + klist_add_tail(&dev->knode_parent, &new_parent->klist_children); set_dev_node(dev, dev_to_node(new_parent)); } @@ -1597,11 +1586,11 @@ int device_move(struct device *dev, struct device *new_parent) device_move_class_links(dev, new_parent, old_parent); if (!kobject_move(&dev->kobj, &old_parent->kobj)) { if (new_parent) - klist_remove(&dev->p->knode_parent); + klist_remove(&dev->knode_parent); dev->parent = old_parent; if (old_parent) { - klist_add_tail(&dev->p->knode_parent, - &old_parent->p->klist_children); + klist_add_tail(&dev->knode_parent, + &old_parent->klist_children); set_dev_node(dev, dev_to_node(old_parent)); } } diff --git a/include/linux/device.h b/include/linux/device.h index c66ceb15acd8..2975351635d3 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -366,6 +366,8 @@ struct device_dma_parameters { }; struct device { + struct klist klist_children; + struct klist_node knode_parent; /* node in sibling list */ struct klist_node knode_driver; struct klist_node knode_bus; struct device *parent; -- cgit v1.2.3 From 926beadb3dfaddccb3348a5b9e6c2a1f8290a220 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 9 Jan 2009 15:06:12 -0800 Subject: Revert "driver core: create a private portion of struct device" This reverts commit 2831fe6f9cc4e16c103504ee09a47a084297c0f3. Turns out that device_initialize shouldn't fail silently. This series needs to be reworked in order to get into proper shape. Reported-by: Stefan Richter Cc: Alan Cox Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 12 ------------ drivers/base/core.c | 8 -------- include/linux/device.h | 3 --- 3 files changed, 23 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 6b20809b5fd4..0a5f055dffba 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -63,18 +63,6 @@ struct class_private { #define to_class(obj) \ container_of(obj, struct class_private, class_subsys.kobj) -/** - * struct device_private - structure to hold the private to the driver core portions of the device structure. - * - * @device - pointer back to the struct class that this structure is - * associated with. - * - * Nothing outside of the driver core should ever touch these fields. - */ -struct device_private { - struct device *device; -}; - /* initialisation functions */ extern int devices_init(void); extern int buses_init(void); diff --git a/drivers/base/core.c b/drivers/base/core.c index 5c2acf7116d7..8079afca4972 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -109,7 +109,6 @@ static struct sysfs_ops dev_sysfs_ops = { static void device_release(struct kobject *kobj) { struct device *dev = to_dev(kobj); - struct device_private *p = dev->p; if (dev->release) dev->release(dev); @@ -121,7 +120,6 @@ static void device_release(struct kobject *kobj) WARN(1, KERN_ERR "Device '%s' does not have a release() " "function, it is broken and must be fixed.\n", dev_name(dev)); - kfree(p); } static struct kobj_type device_ktype = { @@ -538,12 +536,6 @@ static void klist_children_put(struct klist_node *n) */ void device_initialize(struct device *dev) { - dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL); - if (!dev->p) { - WARN_ON(1); - return; - } - dev->p->device = dev; dev->kobj.kset = devices_kset; kobject_init(&dev->kobj, &device_ktype); klist_init(&dev->klist_children, klist_children_get, diff --git a/include/linux/device.h b/include/linux/device.h index 2975351635d3..45e5b1921fbb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -28,7 +28,6 @@ #define BUS_ID_SIZE 20 struct device; -struct device_private; struct device_driver; struct driver_private; struct class; @@ -372,8 +371,6 @@ struct device { struct klist_node knode_bus; struct device *parent; - struct device_private *p; - struct kobject kobj; char bus_id[BUS_ID_SIZE]; /* position on parent bus */ unsigned uevent_suppress:1; -- cgit v1.2.3