]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/bus.c
driver core: struct device - replace bus_id with dev_name(), dev_set_name()
[linux-2.6-omap-h63xx.git] / drivers / base / bus.c
index ef522ae5548092f83ddabcbf36d7a54ad56f7282..83f32b891fa95db9156680a6275cc87ad9620e81 100644 (file)
@@ -333,9 +333,7 @@ static int match_name(struct device *dev, void *data)
 {
        const char *name = data;
 
-       if (strcmp(name, dev->bus_id) == 0)
-               return 1;
-       return 0;
+       return sysfs_streq(name, dev_name(dev));
 }
 
 /**
@@ -463,12 +461,12 @@ int bus_add_device(struct device *dev)
        int error = 0;
 
        if (bus) {
-               pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id);
+               pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev));
                error = device_add_attrs(bus, dev);
                if (error)
                        goto out_put;
                error = sysfs_create_link(&bus->p->devices_kset->kobj,
-                                               &dev->kobj, dev->bus_id);
+                                               &dev->kobj, dev_name(dev));
                if (error)
                        goto out_id;
                error = sysfs_create_link(&dev->kobj,
@@ -484,7 +482,7 @@ int bus_add_device(struct device *dev)
 out_deprecated:
        sysfs_remove_link(&dev->kobj, "subsystem");
 out_subsys:
-       sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id);
+       sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev));
 out_id:
        device_remove_attrs(bus, dev);
 out_put:
@@ -528,13 +526,13 @@ void bus_remove_device(struct device *dev)
                sysfs_remove_link(&dev->kobj, "subsystem");
                remove_deprecated_bus_links(dev);
                sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
-                                 dev->bus_id);
+                                 dev_name(dev));
                device_remove_attrs(dev->bus, dev);
                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);
+                        dev->bus->name, dev_name(dev));
                device_release_driver(dev);
                bus_put(dev->bus);
        }
@@ -982,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);