X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=drivers%2Fbase%2Fbus.c;h=5aee1c0169eafed102c699281b5bb4875fefd20c;hb=0936912274af78a21fd8d54c3f94a50a285cf7f9;hp=937fc100b64a87d5549c3e5afcd90a3c9dae6cca;hpb=7dc72b2842381684b864750af31a5fb168dec764;p=mv-sheeva.git diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 937fc100b64..5aee1c0169e 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -46,10 +46,10 @@ static void bus_put(struct bus_type *bus) kset_put(&bus->p->subsys); } -static ssize_t -drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t drv_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct driver_attribute * drv_attr = to_drv_attr(attr); + struct driver_attribute *drv_attr = to_drv_attr(attr); struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; @@ -58,11 +58,10 @@ drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -drv_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct driver_attribute * drv_attr = to_drv_attr(attr); + struct driver_attribute *drv_attr = to_drv_attr(attr); struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; @@ -80,7 +79,7 @@ static void driver_release(struct kobject *kobj) { struct driver_private *drv_priv = to_driver(kobj); - pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__); + pr_debug("driver: '%s': %s\n", kobject_name(kobj), __func__); kfree(drv_priv); } @@ -89,16 +88,13 @@ static struct kobj_type driver_ktype = { .release = driver_release, }; - /* * sysfs bindings for buses */ - - -static ssize_t -bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_attribute *bus_attr = to_bus_attr(attr); struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; @@ -107,11 +103,10 @@ bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -bus_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_attribute *bus_attr = to_bus_attr(attr); struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; @@ -125,7 +120,7 @@ static struct sysfs_ops bus_sysfs_ops = { .store = bus_attr_store, }; -int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) +int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) { int error; if (bus_get(bus)) { @@ -135,14 +130,16 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) error = -EINVAL; return error; } +EXPORT_SYMBOL_GPL(bus_create_file); -void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) +void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) { if (bus_get(bus)) { sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); bus_put(bus); } } +EXPORT_SYMBOL_GPL(bus_remove_file); static struct kobj_type bus_ktype = { .sysfs_ops = &bus_sysfs_ops, @@ -166,15 +163,6 @@ static struct kset *bus_kset; #ifdef CONFIG_HOTPLUG /* Manually detach a device from its associated driver. */ -static int driver_helper(struct device *dev, void *data) -{ - const char *name = data; - - if (strcmp(name, dev->bus_id) == 0) - return 1; - return 0; -} - static ssize_t driver_unbind(struct device_driver *drv, const char *buf, size_t count) { @@ -182,7 +170,7 @@ static ssize_t driver_unbind(struct device_driver *drv, struct device *dev; int err = -ENODEV; - dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); + dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == drv) { if (dev->parent) /* Needed for USB */ down(&dev->parent->sem); @@ -209,7 +197,7 @@ static ssize_t driver_bind(struct device_driver *drv, struct device *dev; int err = -ENODEV; - dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); + dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == NULL) { if (dev->parent) /* Needed for USB */ down(&dev->parent->sem); @@ -219,10 +207,13 @@ static ssize_t driver_bind(struct device_driver *drv, if (dev->parent) up(&dev->parent->sem); - if (err > 0) /* success */ + if (err > 0) { + /* success */ err = count; - else if (err == 0) /* driver didn't accept device */ + } else if (err == 0) { + /* driver didn't accept device */ err = -ENODEV; + } } put_device(dev); bus_put(bus); @@ -250,7 +241,7 @@ static ssize_t store_drivers_probe(struct bus_type *bus, { struct device *dev; - dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); + dev = bus_find_device_by_name(bus, NULL, buf); if (!dev) return -ENODEV; if (bus_rescan_devices_helper(dev, NULL) != 0) @@ -259,37 +250,36 @@ static ssize_t store_drivers_probe(struct bus_type *bus, } #endif -static struct device * next_device(struct klist_iter * i) +static struct device *next_device(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); return n ? container_of(n, struct device, knode_bus) : NULL; } /** - * bus_for_each_dev - device iterator. - * @bus: bus type. - * @start: device to start iterating from. - * @data: data for the callback. - * @fn: function to be called for each device. + * bus_for_each_dev - device iterator. + * @bus: bus type. + * @start: device to start iterating from. + * @data: data for the callback. + * @fn: function to be called for each device. * - * Iterate over @bus's list of devices, and call @fn for each, - * passing it @data. If @start is not NULL, we use that device to - * begin iterating from. + * Iterate over @bus's list of devices, and call @fn for each, + * passing it @data. If @start is not NULL, we use that device to + * begin iterating from. * - * We check the return of @fn each time. If it returns anything - * other than 0, we break out and return that value. + * We check the return of @fn each time. If it returns anything + * other than 0, we break out and return that value. * - * NOTE: The device that returns a non-zero value is not retained - * in any way, nor is its refcount incremented. If the caller needs - * to retain this data, it should do, and increment the reference - * count in the supplied callback. + * NOTE: The device that returns a non-zero value is not retained + * in any way, nor is its refcount incremented. If the caller needs + * to retain this data, it should do, and increment the reference + * count in the supplied callback. */ - -int bus_for_each_dev(struct bus_type * bus, struct device * start, - void * data, int (*fn)(struct device *, void *)) +int bus_for_each_dev(struct bus_type *bus, struct device *start, + void *data, int (*fn)(struct device *, void *)) { struct klist_iter i; - struct device * dev; + struct device *dev; int error = 0; if (!bus) @@ -302,6 +292,7 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(bus_for_each_dev); /** * bus_find_device - device iterator for locating a particular device. @@ -318,9 +309,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, * if it does. If the callback returns non-zero, this function will * return to the caller and not iterate over any more devices. */ -struct device * bus_find_device(struct bus_type *bus, - struct device *start, void *data, - int (*match)(struct device *, void *)) +struct device *bus_find_device(struct bus_type *bus, + struct device *start, void *data, + int (*match)(struct device *dev, void *data)) { struct klist_iter i; struct device *dev; @@ -336,11 +327,35 @@ struct device * bus_find_device(struct bus_type *bus, klist_iter_exit(&i); return dev; } +EXPORT_SYMBOL_GPL(bus_find_device); +static int match_name(struct device *dev, void *data) +{ + const char *name = data; -static struct device_driver * next_driver(struct klist_iter * i) + return sysfs_streq(name, dev->bus_id); +} + +/** + * bus_find_device_by_name - device iterator for locating a particular device of a specific name + * @bus: bus type + * @start: Device to begin with + * @name: name of the device to match + * + * This is similar to the bus_find_device() function above, but it handles + * searching by a name automatically, no need to write another strcmp matching + * function. + */ +struct device *bus_find_device_by_name(struct bus_type *bus, + struct device *start, const char *name) +{ + return bus_find_device(bus, start, (void *)name, match_name); +} +EXPORT_SYMBOL_GPL(bus_find_device_by_name); + +static struct device_driver *next_driver(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); struct driver_private *drv_priv; if (n) { @@ -351,30 +366,29 @@ static struct device_driver * next_driver(struct klist_iter * i) } /** - * bus_for_each_drv - driver iterator - * @bus: bus we're dealing with. - * @start: driver to start iterating on. - * @data: data to pass to the callback. - * @fn: function to call for each driver. + * bus_for_each_drv - driver iterator + * @bus: bus we're dealing with. + * @start: driver to start iterating on. + * @data: data to pass to the callback. + * @fn: function to call for each driver. * - * This is nearly identical to the device iterator above. - * We iterate over each driver that belongs to @bus, and call - * @fn for each. If @fn returns anything but 0, we break out - * and return it. If @start is not NULL, we use it as the head - * of the list. + * This is nearly identical to the device iterator above. + * We iterate over each driver that belongs to @bus, and call + * @fn for each. If @fn returns anything but 0, we break out + * and return it. If @start is not NULL, we use it as the head + * of the list. * - * NOTE: we don't return the driver that returns a non-zero - * value, nor do we leave the reference count incremented for that - * driver. If the caller needs to know that info, it must set it - * in the callback. It must also be sure to increment the refcount - * so it doesn't disappear before returning to the caller. + * NOTE: we don't return the driver that returns a non-zero + * value, nor do we leave the reference count incremented for that + * driver. If the caller needs to know that info, it must set it + * in the callback. It must also be sure to increment the refcount + * so it doesn't disappear before returning to the caller. */ - -int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, - void * data, int (*fn)(struct device_driver *, void *)) +int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, + void *data, int (*fn)(struct device_driver *, void *)) { struct klist_iter i; - struct device_driver * drv; + struct device_driver *drv; int error = 0; if (!bus) @@ -387,6 +401,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(bus_for_each_drv); static int device_add_attrs(struct bus_type *bus, struct device *dev) { @@ -397,7 +412,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) return 0; for (i = 0; attr_name(bus->dev_attrs[i]); i++) { - error = device_create_file(dev,&bus->dev_attrs[i]); + error = device_create_file(dev, &bus->dev_attrs[i]); if (error) { while (--i >= 0) device_remove_file(dev, &bus->dev_attrs[i]); @@ -407,13 +422,13 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) return error; } -static void device_remove_attrs(struct bus_type * bus, struct device * dev) +static void device_remove_attrs(struct bus_type *bus, struct device *dev) { int i; if (bus->dev_attrs) { for (i = 0; attr_name(bus->dev_attrs[i]); i++) - device_remove_file(dev,&bus->dev_attrs[i]); + device_remove_file(dev, &bus->dev_attrs[i]); } } @@ -434,15 +449,15 @@ static inline void remove_deprecated_bus_links(struct device *dev) { } #endif /** - * bus_add_device - add device to bus - * @dev: device being added + * bus_add_device - add device to bus + * @dev: device being added * - * - Add the device to its bus's list of devices. - * - Create link to device's bus. + * - Add the device to its bus's list of devices. + * - Create link to device's bus. */ -int bus_add_device(struct device * dev) +int bus_add_device(struct device *dev) { - struct bus_type * bus = bus_get(dev->bus); + struct bus_type *bus = bus_get(dev->bus); int error = 0; if (bus) { @@ -476,56 +491,54 @@ out_put: } /** - * bus_attach_device - add device to bus - * @dev: device tried to attach to a driver + * bus_attach_device - add device to bus + * @dev: device tried to attach to a driver * - * - Add device to bus's list of devices. - * - Try to attach to driver. + * - Add device to bus's list of devices. + * - Try to attach to driver. */ -void bus_attach_device(struct device * dev) +void bus_attach_device(struct device *dev) { struct bus_type *bus = dev->bus; int ret = 0; if (bus) { - dev->is_registered = 1; if (bus->p->drivers_autoprobe) ret = device_attach(dev); WARN_ON(ret < 0); if (ret >= 0) klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); - else - dev->is_registered = 0; } } /** - * bus_remove_device - remove device from bus - * @dev: device to be removed + * bus_remove_device - remove device from bus + * @dev: device to be removed * - * - Remove symlink from bus's directory. - * - Delete device from bus's list. - * - Detach from its driver. - * - Drop reference taken in bus_add_device(). + * - Remove symlink from bus's directory. + * - Delete device from bus's list. + * - Detach from its driver. + * - Drop reference taken in bus_add_device(). */ -void bus_remove_device(struct device * dev) +void bus_remove_device(struct device *dev) { if (dev->bus) { sysfs_remove_link(&dev->kobj, "subsystem"); remove_deprecated_bus_links(dev); - sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id); + sysfs_remove_link(&dev->bus->p->devices_kset->kobj, + dev->bus_id); device_remove_attrs(dev->bus, dev); - if (dev->is_registered) { - dev->is_registered = 0; + if (klist_node_attached(&dev->knode_bus)) klist_del(&dev->knode_bus); - } - pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id); + + pr_debug("bus: '%s': remove device %s\n", + dev->bus->name, dev->bus_id); device_release_driver(dev); bus_put(dev->bus); } } -static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) +static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv) { int error = 0; int i; @@ -534,19 +547,19 @@ static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) for (i = 0; attr_name(bus->drv_attrs[i]); i++) { error = driver_create_file(drv, &bus->drv_attrs[i]); if (error) - goto Err; + goto err; } } - Done: +done: return error; - Err: +err: while (--i >= 0) driver_remove_file(drv, &bus->drv_attrs[i]); - goto Done; + goto done; } - -static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv) +static void driver_remove_attrs(struct bus_type *bus, + struct device_driver *drv) { int i; @@ -623,9 +636,8 @@ static ssize_t driver_uevent_store(struct device_driver *drv, static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); /** - * bus_add_driver - Add a driver to the bus. - * @drv: driver. - * + * bus_add_driver - Add a driver to the bus. + * @drv: driver. */ int bus_add_driver(struct device_driver *drv) { @@ -640,20 +652,18 @@ int bus_add_driver(struct device_driver *drv) pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - error = kobject_set_name(&priv->kobj, "%s", drv->name); - if (error) + if (!priv) { + error = -ENOMEM; goto out_put_bus; - priv->kobj.kset = bus->p->drivers_kset; - priv->kobj.ktype = &driver_ktype; + } klist_init(&priv->klist_devices, NULL, NULL); priv->driver = drv; drv->p = priv; - error = kobject_register(&priv->kobj); + priv->kobj.kset = bus->p->drivers_kset; + error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL, + "%s", drv->name); if (error) - goto out_put_bus; + goto out_unregister; if (drv->bus->p->drivers_autoprobe) { error = driver_attach(drv); @@ -666,39 +676,39 @@ int bus_add_driver(struct device_driver *drv) error = driver_create_file(drv, &driver_attr_uevent); if (error) { printk(KERN_ERR "%s: uevent attr (%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } error = driver_add_attrs(bus, drv); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } error = add_bind_files(drv); if (error) { /* Ditto */ printk(KERN_ERR "%s: add_bind_files(%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } + kobject_uevent(&priv->kobj, KOBJ_ADD); return error; out_unregister: - kobject_unregister(&priv->kobj); + kobject_put(&priv->kobj); out_put_bus: bus_put(bus); return error; } /** - * bus_remove_driver - delete driver from bus's knowledge. - * @drv: driver. + * bus_remove_driver - delete driver from bus's knowledge. + * @drv: driver. * - * Detach the driver from the devices it controls, and remove - * it from its bus's list of drivers. Finally, we drop the reference - * to the bus we took in bus_add_driver(). + * Detach the driver from the devices it controls, and remove + * it from its bus's list of drivers. Finally, we drop the reference + * to the bus we took in bus_add_driver(). */ - -void bus_remove_driver(struct device_driver * drv) +void bus_remove_driver(struct device_driver *drv) { if (!drv->bus) return; @@ -710,14 +720,13 @@ void bus_remove_driver(struct device_driver * drv) pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); driver_detach(drv); module_remove_driver(drv); - kobject_unregister(&drv->p->kobj); + kobject_put(&drv->p->kobj); bus_put(drv->bus); } - /* Helper for bus_rescan_devices's iter */ static int __must_check bus_rescan_devices_helper(struct device *dev, - void *data) + void *data) { int ret = 0; @@ -739,10 +748,11 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, * attached and rescan it against existing drivers to see if it matches * any by calling device_attach() for the unbound devices. */ -int bus_rescan_devices(struct bus_type * bus) +int bus_rescan_devices(struct bus_type *bus) { return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); } +EXPORT_SYMBOL_GPL(bus_rescan_devices); /** * device_reprobe - remove driver for a device and probe for a new driver @@ -767,55 +777,55 @@ int device_reprobe(struct device *dev) EXPORT_SYMBOL_GPL(device_reprobe); /** - * find_bus - locate bus by name. - * @name: name of bus. + * find_bus - locate bus by name. + * @name: name of bus. * - * Call kset_find_obj() to iterate over list of buses to - * find a bus by name. Return bus if found. + * Call kset_find_obj() to iterate over list of buses to + * find a bus by name. Return bus if found. * - * Note that kset_find_obj increments bus' reference count. + * Note that kset_find_obj increments bus' reference count. */ #if 0 -struct bus_type * find_bus(char * name) +struct bus_type *find_bus(char *name) { - struct kobject * k = kset_find_obj(bus_kset, name); + struct kobject *k = kset_find_obj(bus_kset, name); return k ? to_bus(k) : NULL; } #endif /* 0 */ /** - * bus_add_attrs - Add default attributes for this bus. - * @bus: Bus that has just been registered. + * bus_add_attrs - Add default attributes for this bus. + * @bus: Bus that has just been registered. */ -static int bus_add_attrs(struct bus_type * bus) +static int bus_add_attrs(struct bus_type *bus) { int error = 0; int i; if (bus->bus_attrs) { for (i = 0; attr_name(bus->bus_attrs[i]); i++) { - error = bus_create_file(bus,&bus->bus_attrs[i]); + error = bus_create_file(bus, &bus->bus_attrs[i]); if (error) - goto Err; + goto err; } } - Done: +done: return error; - Err: +err: while (--i >= 0) - bus_remove_file(bus,&bus->bus_attrs[i]); - goto Done; + bus_remove_file(bus, &bus->bus_attrs[i]); + goto done; } -static void bus_remove_attrs(struct bus_type * bus) +static void bus_remove_attrs(struct bus_type *bus) { int i; if (bus->bus_attrs) { for (i = 0; attr_name(bus->bus_attrs[i]); i++) - bus_remove_file(bus,&bus->bus_attrs[i]); + bus_remove_file(bus, &bus->bus_attrs[i]); } } @@ -845,14 +855,14 @@ static ssize_t bus_uevent_store(struct bus_type *bus, static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); /** - * bus_register - register a bus with the system. - * @bus: bus. + * bus_register - register a bus with the system. + * @bus: bus. * - * Once we have that, we registered the bus with the kobject - * infrastructure, then register the children subsystems it has: - * the devices and drivers that belong to the bus. + * Once we have that, we registered the bus with the kobject + * infrastructure, then register the children subsystems it has: + * the devices and drivers that belong to the bus. */ -int bus_register(struct bus_type * bus) +int bus_register(struct bus_type *bus) { int retval; struct bus_type_private *priv; @@ -924,15 +934,16 @@ bus_uevent_fail: out: return retval; } +EXPORT_SYMBOL_GPL(bus_register); /** - * bus_unregister - remove a bus from the system - * @bus: bus. + * bus_unregister - remove a bus from the system + * @bus: bus. * - * Unregister the child subsystems and the bus itself. - * Finally, we call bus_put() to release the refcount + * Unregister the child subsystems and the bus itself. + * Finally, we call bus_put() to release the refcount */ -void bus_unregister(struct bus_type * bus) +void bus_unregister(struct bus_type *bus) { pr_debug("bus: '%s': unregistering\n", bus->name); bus_remove_attrs(bus); @@ -943,6 +954,7 @@ void bus_unregister(struct bus_type * bus) kset_unregister(&bus->p->subsys); kfree(bus->p); } +EXPORT_SYMBOL_GPL(bus_unregister); int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) { @@ -968,6 +980,56 @@ struct klist *bus_get_device_klist(struct bus_type *bus) } EXPORT_SYMBOL_GPL(bus_get_device_klist); +/* + * Yes, this forcably breaks the klist abstraction temporarily. It + * just wants to sort the klist, not change reference counts and + * take/drop locks rapidly in the process. It does all this while + * holding the lock for the list, so objects can't otherwise be + * added/removed while we're swizzling. + */ +static void device_insertion_sort_klist(struct device *a, struct list_head *list, + int (*compare)(const struct device *a, + const struct device *b)) +{ + struct list_head *pos; + struct klist_node *n; + struct device *b; + + list_for_each(pos, list) { + n = container_of(pos, struct klist_node, n_node); + b = container_of(n, struct device, knode_bus); + if (compare(a, b) <= 0) { + list_move_tail(&a->knode_bus.n_node, + &b->knode_bus.n_node); + return; + } + } + list_move_tail(&a->knode_bus.n_node, list); +} + +void bus_sort_breadthfirst(struct bus_type *bus, + int (*compare)(const struct device *a, + const struct device *b)) +{ + LIST_HEAD(sorted_devices); + struct list_head *pos, *tmp; + struct klist_node *n; + struct device *dev; + struct klist *device_klist; + + device_klist = bus_get_device_klist(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 = container_of(n, struct device, knode_bus); + device_insertion_sort_klist(dev, &sorted_devices, compare); + } + list_splice(&sorted_devices, &device_klist->k_list); + spin_unlock(&device_klist->k_lock); +} +EXPORT_SYMBOL_GPL(bus_sort_breadthfirst); + int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); @@ -975,15 +1037,3 @@ int __init buses_init(void) return -ENOMEM; return 0; } - - -EXPORT_SYMBOL_GPL(bus_for_each_dev); -EXPORT_SYMBOL_GPL(bus_find_device); -EXPORT_SYMBOL_GPL(bus_for_each_drv); - -EXPORT_SYMBOL_GPL(bus_register); -EXPORT_SYMBOL_GPL(bus_unregister); -EXPORT_SYMBOL_GPL(bus_rescan_devices); - -EXPORT_SYMBOL_GPL(bus_create_file); -EXPORT_SYMBOL_GPL(bus_remove_file);