allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / base / bus.c
blobdca734819e50cc670439f22806eac6198e8c29eb
1 /*
2 * bus.c - bus driver management
4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs
7 * This file is released under the GPLv2
9 */
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/string.h>
16 #include "base.h"
17 #include "power/power.h"
19 #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
20 #define to_bus(obj) container_of(obj, struct bus_type, subsys.kobj)
23 * sysfs bindings for drivers
26 #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
27 #define to_driver(obj) container_of(obj, struct device_driver, kobj)
30 static int __must_check bus_rescan_devices_helper(struct device *dev,
31 void *data);
33 static ssize_t
34 drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
36 struct driver_attribute * drv_attr = to_drv_attr(attr);
37 struct device_driver * drv = to_driver(kobj);
38 ssize_t ret = -EIO;
40 if (drv_attr->show)
41 ret = drv_attr->show(drv, buf);
42 return ret;
45 static ssize_t
46 drv_attr_store(struct kobject * kobj, struct attribute * attr,
47 const char * buf, size_t count)
49 struct driver_attribute * drv_attr = to_drv_attr(attr);
50 struct device_driver * drv = to_driver(kobj);
51 ssize_t ret = -EIO;
53 if (drv_attr->store)
54 ret = drv_attr->store(drv, buf, count);
55 return ret;
58 static struct sysfs_ops driver_sysfs_ops = {
59 .show = drv_attr_show,
60 .store = drv_attr_store,
64 static void driver_release(struct kobject * kobj)
67 * Yes this is an empty release function, it is this way because struct
68 * device is always a static object, not a dynamic one. Yes, this is
69 * not nice and bad, but remember, drivers are code, reference counted
70 * by the module count, not a device, which is really data. And yes,
71 * in the future I do want to have all drivers be created dynamically,
72 * and am working toward that goal, but it will take a bit longer...
74 * But do not let this example give _anyone_ the idea that they can
75 * create a release function without any code in it at all, to do that
76 * is almost always wrong. If you have any questions about this,
77 * please send an email to <greg@kroah.com>
81 static struct kobj_type ktype_driver = {
82 .sysfs_ops = &driver_sysfs_ops,
83 .release = driver_release,
88 * sysfs bindings for buses
92 static ssize_t
93 bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
95 struct bus_attribute * bus_attr = to_bus_attr(attr);
96 struct bus_type * bus = to_bus(kobj);
97 ssize_t ret = 0;
99 if (bus_attr->show)
100 ret = bus_attr->show(bus, buf);
101 return ret;
104 static ssize_t
105 bus_attr_store(struct kobject * kobj, struct attribute * attr,
106 const char * buf, size_t count)
108 struct bus_attribute * bus_attr = to_bus_attr(attr);
109 struct bus_type * bus = to_bus(kobj);
110 ssize_t ret = 0;
112 if (bus_attr->store)
113 ret = bus_attr->store(bus, buf, count);
114 return ret;
117 static struct sysfs_ops bus_sysfs_ops = {
118 .show = bus_attr_show,
119 .store = bus_attr_store,
122 int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
124 int error;
125 if (get_bus(bus)) {
126 error = sysfs_create_file(&bus->subsys.kobj, &attr->attr);
127 put_bus(bus);
128 } else
129 error = -EINVAL;
130 return error;
133 void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
135 if (get_bus(bus)) {
136 sysfs_remove_file(&bus->subsys.kobj, &attr->attr);
137 put_bus(bus);
141 static struct kobj_type ktype_bus = {
142 .sysfs_ops = &bus_sysfs_ops,
146 static decl_subsys(bus, &ktype_bus, NULL);
149 #ifdef CONFIG_HOTPLUG
150 /* Manually detach a device from its associated driver. */
151 static int driver_helper(struct device *dev, void *data)
153 const char *name = data;
155 if (strcmp(name, dev->bus_id) == 0)
156 return 1;
157 return 0;
160 static ssize_t driver_unbind(struct device_driver *drv,
161 const char *buf, size_t count)
163 struct bus_type *bus = get_bus(drv->bus);
164 struct device *dev;
165 int err = -ENODEV;
167 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
168 if (dev && dev->driver == drv) {
169 if (dev->parent) /* Needed for USB */
170 down(&dev->parent->sem);
171 device_release_driver(dev);
172 if (dev->parent)
173 up(&dev->parent->sem);
174 err = count;
176 put_device(dev);
177 put_bus(bus);
178 return err;
180 static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
183 * Manually attach a device to a driver.
184 * Note: the driver must want to bind to the device,
185 * it is not possible to override the driver's id table.
187 static ssize_t driver_bind(struct device_driver *drv,
188 const char *buf, size_t count)
190 struct bus_type *bus = get_bus(drv->bus);
191 struct device *dev;
192 int err = -ENODEV;
194 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
195 if (dev && dev->driver == NULL) {
196 if (dev->parent) /* Needed for USB */
197 down(&dev->parent->sem);
198 down(&dev->sem);
199 err = driver_probe_device(drv, dev);
200 up(&dev->sem);
201 if (dev->parent)
202 up(&dev->parent->sem);
204 if (err > 0) /* success */
205 err = count;
206 else if (err == 0) /* driver didn't accept device */
207 err = -ENODEV;
209 put_device(dev);
210 put_bus(bus);
211 return err;
213 static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
215 static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
217 return sprintf(buf, "%d\n", bus->drivers_autoprobe);
220 static ssize_t store_drivers_autoprobe(struct bus_type *bus,
221 const char *buf, size_t count)
223 if (buf[0] == '0')
224 bus->drivers_autoprobe = 0;
225 else
226 bus->drivers_autoprobe = 1;
227 return count;
230 static ssize_t store_drivers_probe(struct bus_type *bus,
231 const char *buf, size_t count)
233 struct device *dev;
235 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
236 if (!dev)
237 return -ENODEV;
238 if (bus_rescan_devices_helper(dev, NULL) != 0)
239 return -EINVAL;
240 return count;
242 #endif
244 static struct device * next_device(struct klist_iter * i)
246 struct klist_node * n = klist_next(i);
247 return n ? container_of(n, struct device, knode_bus) : NULL;
251 * bus_for_each_dev - device iterator.
252 * @bus: bus type.
253 * @start: device to start iterating from.
254 * @data: data for the callback.
255 * @fn: function to be called for each device.
257 * Iterate over @bus's list of devices, and call @fn for each,
258 * passing it @data. If @start is not NULL, we use that device to
259 * begin iterating from.
261 * We check the return of @fn each time. If it returns anything
262 * other than 0, we break out and return that value.
264 * NOTE: The device that returns a non-zero value is not retained
265 * in any way, nor is its refcount incremented. If the caller needs
266 * to retain this data, it should do, and increment the reference
267 * count in the supplied callback.
270 int bus_for_each_dev(struct bus_type * bus, struct device * start,
271 void * data, int (*fn)(struct device *, void *))
273 struct klist_iter i;
274 struct device * dev;
275 int error = 0;
277 if (!bus)
278 return -EINVAL;
280 klist_iter_init_node(&bus->klist_devices, &i,
281 (start ? &start->knode_bus : NULL));
282 while ((dev = next_device(&i)) && !error)
283 error = fn(dev, data);
284 klist_iter_exit(&i);
285 return error;
289 * bus_find_device - device iterator for locating a particular device.
290 * @bus: bus type
291 * @start: Device to begin with
292 * @data: Data to pass to match function
293 * @match: Callback function to check device
295 * This is similar to the bus_for_each_dev() function above, but it
296 * returns a reference to a device that is 'found' for later use, as
297 * determined by the @match callback.
299 * The callback should return 0 if the device doesn't match and non-zero
300 * if it does. If the callback returns non-zero, this function will
301 * return to the caller and not iterate over any more devices.
303 struct device * bus_find_device(struct bus_type *bus,
304 struct device *start, void *data,
305 int (*match)(struct device *, void *))
307 struct klist_iter i;
308 struct device *dev;
310 if (!bus)
311 return NULL;
313 klist_iter_init_node(&bus->klist_devices, &i,
314 (start ? &start->knode_bus : NULL));
315 while ((dev = next_device(&i)))
316 if (match(dev, data) && get_device(dev))
317 break;
318 klist_iter_exit(&i);
319 return dev;
323 static struct device_driver * next_driver(struct klist_iter * i)
325 struct klist_node * n = klist_next(i);
326 return n ? container_of(n, struct device_driver, knode_bus) : NULL;
330 * bus_for_each_drv - driver iterator
331 * @bus: bus we're dealing with.
332 * @start: driver to start iterating on.
333 * @data: data to pass to the callback.
334 * @fn: function to call for each driver.
336 * This is nearly identical to the device iterator above.
337 * We iterate over each driver that belongs to @bus, and call
338 * @fn for each. If @fn returns anything but 0, we break out
339 * and return it. If @start is not NULL, we use it as the head
340 * of the list.
342 * NOTE: we don't return the driver that returns a non-zero
343 * value, nor do we leave the reference count incremented for that
344 * driver. If the caller needs to know that info, it must set it
345 * in the callback. It must also be sure to increment the refcount
346 * so it doesn't disappear before returning to the caller.
349 int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
350 void * data, int (*fn)(struct device_driver *, void *))
352 struct klist_iter i;
353 struct device_driver * drv;
354 int error = 0;
356 if (!bus)
357 return -EINVAL;
359 klist_iter_init_node(&bus->klist_drivers, &i,
360 start ? &start->knode_bus : NULL);
361 while ((drv = next_driver(&i)) && !error)
362 error = fn(drv, data);
363 klist_iter_exit(&i);
364 return error;
367 static int device_add_attrs(struct bus_type *bus, struct device *dev)
369 int error = 0;
370 int i;
372 if (!bus->dev_attrs)
373 return 0;
375 for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
376 error = device_create_file(dev,&bus->dev_attrs[i]);
377 if (error) {
378 while (--i >= 0)
379 device_remove_file(dev, &bus->dev_attrs[i]);
380 break;
383 return error;
386 static void device_remove_attrs(struct bus_type * bus, struct device * dev)
388 int i;
390 if (bus->dev_attrs) {
391 for (i = 0; attr_name(bus->dev_attrs[i]); i++)
392 device_remove_file(dev,&bus->dev_attrs[i]);
396 #ifdef CONFIG_SYSFS_DEPRECATED
397 static int make_deprecated_bus_links(struct device *dev)
399 return sysfs_create_link(&dev->kobj,
400 &dev->bus->subsys.kobj, "bus");
403 static void remove_deprecated_bus_links(struct device *dev)
405 sysfs_remove_link(&dev->kobj, "bus");
407 #else
408 static inline int make_deprecated_bus_links(struct device *dev) { return 0; }
409 static inline void remove_deprecated_bus_links(struct device *dev) { }
410 #endif
413 * bus_add_device - add device to bus
414 * @dev: device being added
416 * - Add the device to its bus's list of devices.
417 * - Create link to device's bus.
419 int bus_add_device(struct device * dev)
421 struct bus_type * bus = get_bus(dev->bus);
422 int error = 0;
424 if (bus) {
425 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
426 error = device_add_attrs(bus, dev);
427 if (error)
428 goto out_put;
429 error = sysfs_create_link(&bus->devices.kobj,
430 &dev->kobj, dev->bus_id);
431 if (error)
432 goto out_id;
433 error = sysfs_create_link(&dev->kobj,
434 &dev->bus->subsys.kobj, "subsystem");
435 if (error)
436 goto out_subsys;
437 error = make_deprecated_bus_links(dev);
438 if (error)
439 goto out_deprecated;
441 return 0;
443 out_deprecated:
444 sysfs_remove_link(&dev->kobj, "subsystem");
445 out_subsys:
446 sysfs_remove_link(&bus->devices.kobj, dev->bus_id);
447 out_id:
448 device_remove_attrs(bus, dev);
449 out_put:
450 put_bus(dev->bus);
451 return error;
455 * bus_attach_device - add device to bus
456 * @dev: device tried to attach to a driver
458 * - Add device to bus's list of devices.
459 * - Try to attach to driver.
461 void bus_attach_device(struct device * dev)
463 struct bus_type *bus = dev->bus;
464 int ret = 0;
466 if (bus) {
467 dev->is_registered = 1;
468 if (bus->drivers_autoprobe)
469 ret = device_attach(dev);
470 WARN_ON(ret < 0);
471 if (ret >= 0)
472 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
473 else
474 dev->is_registered = 0;
479 * bus_remove_device - remove device from bus
480 * @dev: device to be removed
482 * - Remove symlink from bus's directory.
483 * - Delete device from bus's list.
484 * - Detach from its driver.
485 * - Drop reference taken in bus_add_device().
487 void bus_remove_device(struct device * dev)
489 if (dev->bus) {
490 sysfs_remove_link(&dev->kobj, "subsystem");
491 remove_deprecated_bus_links(dev);
492 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
493 device_remove_attrs(dev->bus, dev);
494 if (dev->is_registered) {
495 dev->is_registered = 0;
496 klist_del(&dev->knode_bus);
498 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
499 device_release_driver(dev);
500 put_bus(dev->bus);
504 static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
506 int error = 0;
507 int i;
509 if (bus->drv_attrs) {
510 for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
511 error = driver_create_file(drv, &bus->drv_attrs[i]);
512 if (error)
513 goto Err;
516 Done:
517 return error;
518 Err:
519 while (--i >= 0)
520 driver_remove_file(drv, &bus->drv_attrs[i]);
521 goto Done;
525 static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
527 int i;
529 if (bus->drv_attrs) {
530 for (i = 0; attr_name(bus->drv_attrs[i]); i++)
531 driver_remove_file(drv, &bus->drv_attrs[i]);
535 #ifdef CONFIG_HOTPLUG
537 * Thanks to drivers making their tables __devinit, we can't allow manual
538 * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled.
540 static int __must_check add_bind_files(struct device_driver *drv)
542 int ret;
544 ret = driver_create_file(drv, &driver_attr_unbind);
545 if (ret == 0) {
546 ret = driver_create_file(drv, &driver_attr_bind);
547 if (ret)
548 driver_remove_file(drv, &driver_attr_unbind);
550 return ret;
553 static void remove_bind_files(struct device_driver *drv)
555 driver_remove_file(drv, &driver_attr_bind);
556 driver_remove_file(drv, &driver_attr_unbind);
559 static int add_probe_files(struct bus_type *bus)
561 int retval;
563 bus->drivers_probe_attr.attr.name = "drivers_probe";
564 bus->drivers_probe_attr.attr.mode = S_IWUSR;
565 bus->drivers_probe_attr.attr.owner = bus->owner;
566 bus->drivers_probe_attr.store = store_drivers_probe;
567 retval = bus_create_file(bus, &bus->drivers_probe_attr);
568 if (retval)
569 goto out;
571 bus->drivers_autoprobe_attr.attr.name = "drivers_autoprobe";
572 bus->drivers_autoprobe_attr.attr.mode = S_IWUSR | S_IRUGO;
573 bus->drivers_autoprobe_attr.attr.owner = bus->owner;
574 bus->drivers_autoprobe_attr.show = show_drivers_autoprobe;
575 bus->drivers_autoprobe_attr.store = store_drivers_autoprobe;
576 retval = bus_create_file(bus, &bus->drivers_autoprobe_attr);
577 if (retval)
578 bus_remove_file(bus, &bus->drivers_probe_attr);
579 out:
580 return retval;
583 static void remove_probe_files(struct bus_type *bus)
585 bus_remove_file(bus, &bus->drivers_autoprobe_attr);
586 bus_remove_file(bus, &bus->drivers_probe_attr);
588 #else
589 static inline int add_bind_files(struct device_driver *drv) { return 0; }
590 static inline void remove_bind_files(struct device_driver *drv) {}
591 static inline int add_probe_files(struct bus_type *bus) { return 0; }
592 static inline void remove_probe_files(struct bus_type *bus) {}
593 #endif
596 * bus_add_driver - Add a driver to the bus.
597 * @drv: driver.
600 int bus_add_driver(struct device_driver *drv)
602 struct bus_type * bus = get_bus(drv->bus);
603 int error = 0;
605 if (!bus)
606 return -EINVAL;
608 pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
609 error = kobject_set_name(&drv->kobj, "%s", drv->name);
610 if (error)
611 goto out_put_bus;
612 drv->kobj.kset = &bus->drivers;
613 if ((error = kobject_register(&drv->kobj)))
614 goto out_put_bus;
616 if (drv->bus->drivers_autoprobe) {
617 error = driver_attach(drv);
618 if (error)
619 goto out_unregister;
621 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
622 module_add_driver(drv->owner, drv);
624 error = driver_add_attrs(bus, drv);
625 if (error) {
626 /* How the hell do we get out of this pickle? Give up */
627 printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n",
628 __FUNCTION__, drv->name);
630 error = add_bind_files(drv);
631 if (error) {
632 /* Ditto */
633 printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
634 __FUNCTION__, drv->name);
637 return error;
638 out_unregister:
639 kobject_unregister(&drv->kobj);
640 out_put_bus:
641 put_bus(bus);
642 return error;
646 * bus_remove_driver - delete driver from bus's knowledge.
647 * @drv: driver.
649 * Detach the driver from the devices it controls, and remove
650 * it from its bus's list of drivers. Finally, we drop the reference
651 * to the bus we took in bus_add_driver().
654 void bus_remove_driver(struct device_driver * drv)
656 if (!drv->bus)
657 return;
659 remove_bind_files(drv);
660 driver_remove_attrs(drv->bus, drv);
661 klist_remove(&drv->knode_bus);
662 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
663 driver_detach(drv);
664 module_remove_driver(drv);
665 kobject_unregister(&drv->kobj);
666 put_bus(drv->bus);
670 /* Helper for bus_rescan_devices's iter */
671 static int __must_check bus_rescan_devices_helper(struct device *dev,
672 void *data)
674 int ret = 0;
676 if (!dev->driver) {
677 if (dev->parent) /* Needed for USB */
678 down(&dev->parent->sem);
679 ret = device_attach(dev);
680 if (dev->parent)
681 up(&dev->parent->sem);
683 return ret < 0 ? ret : 0;
687 * bus_rescan_devices - rescan devices on the bus for possible drivers
688 * @bus: the bus to scan.
690 * This function will look for devices on the bus with no driver
691 * attached and rescan it against existing drivers to see if it matches
692 * any by calling device_attach() for the unbound devices.
694 int bus_rescan_devices(struct bus_type * bus)
696 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
700 * device_reprobe - remove driver for a device and probe for a new driver
701 * @dev: the device to reprobe
703 * This function detaches the attached driver (if any) for the given
704 * device and restarts the driver probing process. It is intended
705 * to use if probing criteria changed during a devices lifetime and
706 * driver attachment should change accordingly.
708 int device_reprobe(struct device *dev)
710 if (dev->driver) {
711 if (dev->parent) /* Needed for USB */
712 down(&dev->parent->sem);
713 device_release_driver(dev);
714 if (dev->parent)
715 up(&dev->parent->sem);
717 return bus_rescan_devices_helper(dev, NULL);
719 EXPORT_SYMBOL_GPL(device_reprobe);
721 struct bus_type *get_bus(struct bus_type *bus)
723 return bus ? container_of(subsys_get(&bus->subsys),
724 struct bus_type, subsys) : NULL;
727 void put_bus(struct bus_type * bus)
729 subsys_put(&bus->subsys);
734 * find_bus - locate bus by name.
735 * @name: name of bus.
737 * Call kset_find_obj() to iterate over list of buses to
738 * find a bus by name. Return bus if found.
740 * Note that kset_find_obj increments bus' reference count.
742 #if 0
743 struct bus_type * find_bus(char * name)
745 struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
746 return k ? to_bus(k) : NULL;
748 #endif /* 0 */
752 * bus_add_attrs - Add default attributes for this bus.
753 * @bus: Bus that has just been registered.
756 static int bus_add_attrs(struct bus_type * bus)
758 int error = 0;
759 int i;
761 if (bus->bus_attrs) {
762 for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
763 if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
764 goto Err;
767 Done:
768 return error;
769 Err:
770 while (--i >= 0)
771 bus_remove_file(bus,&bus->bus_attrs[i]);
772 goto Done;
775 static void bus_remove_attrs(struct bus_type * bus)
777 int i;
779 if (bus->bus_attrs) {
780 for (i = 0; attr_name(bus->bus_attrs[i]); i++)
781 bus_remove_file(bus,&bus->bus_attrs[i]);
785 static void klist_devices_get(struct klist_node *n)
787 struct device *dev = container_of(n, struct device, knode_bus);
789 get_device(dev);
792 static void klist_devices_put(struct klist_node *n)
794 struct device *dev = container_of(n, struct device, knode_bus);
796 put_device(dev);
800 * bus_register - register a bus with the system.
801 * @bus: bus.
803 * Once we have that, we registered the bus with the kobject
804 * infrastructure, then register the children subsystems it has:
805 * the devices and drivers that belong to the bus.
807 int bus_register(struct bus_type * bus)
809 int retval;
811 BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier);
813 retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name);
814 if (retval)
815 goto out;
817 subsys_set_kset(bus, bus_subsys);
818 retval = subsystem_register(&bus->subsys);
819 if (retval)
820 goto out;
822 kobject_set_name(&bus->devices.kobj, "devices");
823 bus->devices.kobj.parent = &bus->subsys.kobj;
824 retval = kset_register(&bus->devices);
825 if (retval)
826 goto bus_devices_fail;
828 kobject_set_name(&bus->drivers.kobj, "drivers");
829 bus->drivers.kobj.parent = &bus->subsys.kobj;
830 bus->drivers.ktype = &ktype_driver;
831 retval = kset_register(&bus->drivers);
832 if (retval)
833 goto bus_drivers_fail;
835 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
836 klist_init(&bus->klist_drivers, NULL, NULL);
838 bus->drivers_autoprobe = 1;
839 retval = add_probe_files(bus);
840 if (retval)
841 goto bus_probe_files_fail;
843 retval = bus_add_attrs(bus);
844 if (retval)
845 goto bus_attrs_fail;
847 pr_debug("bus type '%s' registered\n", bus->name);
848 return 0;
850 bus_attrs_fail:
851 remove_probe_files(bus);
852 bus_probe_files_fail:
853 kset_unregister(&bus->drivers);
854 bus_drivers_fail:
855 kset_unregister(&bus->devices);
856 bus_devices_fail:
857 subsystem_unregister(&bus->subsys);
858 out:
859 return retval;
863 * bus_unregister - remove a bus from the system
864 * @bus: bus.
866 * Unregister the child subsystems and the bus itself.
867 * Finally, we call put_bus() to release the refcount
869 void bus_unregister(struct bus_type * bus)
871 pr_debug("bus %s: unregistering\n", bus->name);
872 bus_remove_attrs(bus);
873 remove_probe_files(bus);
874 kset_unregister(&bus->drivers);
875 kset_unregister(&bus->devices);
876 subsystem_unregister(&bus->subsys);
879 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
881 return blocking_notifier_chain_register(&bus->bus_notifier, nb);
883 EXPORT_SYMBOL_GPL(bus_register_notifier);
885 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
887 return blocking_notifier_chain_unregister(&bus->bus_notifier, nb);
889 EXPORT_SYMBOL_GPL(bus_unregister_notifier);
891 int __init buses_init(void)
893 return subsystem_register(&bus_subsys);
897 EXPORT_SYMBOL_GPL(bus_for_each_dev);
898 EXPORT_SYMBOL_GPL(bus_find_device);
899 EXPORT_SYMBOL_GPL(bus_for_each_drv);
901 EXPORT_SYMBOL_GPL(bus_register);
902 EXPORT_SYMBOL_GPL(bus_unregister);
903 EXPORT_SYMBOL_GPL(bus_rescan_devices);
905 EXPORT_SYMBOL_GPL(bus_create_file);
906 EXPORT_SYMBOL_GPL(bus_remove_file);