+decl_subsys(bus, &ktype_bus, NULL);
+
+static int __bus_for_each_dev(struct bus_type *bus, struct device *start,
+ void *data, int (*fn)(struct device *, void *))
+{
+ struct list_head *head;
+ struct device *dev;
+ int error = 0;
+
+ if (!(bus = get_bus(bus)))
+ return -EINVAL;
+
+ head = &bus->devices.list;
+ dev = list_prepare_entry(start, head, bus_list);
+ list_for_each_entry_continue(dev, head, bus_list) {
+ get_device(dev);
+ error = fn(dev, data);
+ put_device(dev);
+ if (error)
+ break;
+ }
+ put_bus(bus);
+ return error;
+}
+
+static int __bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
+ void * data, int (*fn)(struct device_driver *, void *))
+{
+ struct list_head *head;
+ struct device_driver *drv;
+ int error = 0;
+
+ if (!(bus = get_bus(bus)))
+ return -EINVAL;
+
+ head = &bus->drivers.list;
+ drv = list_prepare_entry(start, head, kobj.entry);
+ list_for_each_entry_continue(drv, head, kobj.entry) {
+ get_driver(drv);
+ error = fn(drv, data);
+ put_driver(drv);
+ if (error)
+ break;
+ }
+ put_bus(bus);
+ return error;
+}