/** * 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. */ int bus_register(struct bus_type * bus) { int retval = -ENOMEM; struct blocking_notifier_head *notifier_head; notifier_head = alloc_save_notifier_for_bus(bus); if (!notifier_head) goto out; BLOCKING_INIT_NOTIFIER_HEAD(notifier_head); retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name); if (retval) goto out; subsys_set_kset(bus, bus_subsys); retval = subsystem_register(&bus->subsys); if (retval) goto out; kobject_set_name(&bus->devices.kobj, "devices"); bus->devices.subsys = &bus->subsys; retval = kset_register(&bus->devices); if (retval) goto bus_devices_fail; kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.subsys = &bus->subsys; bus->drivers.ktype = &ktype_driver; retval = kset_register(&bus->drivers); if (retval) goto bus_drivers_fail; klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); retval = add_probe_files(bus); if (retval) goto bus_probe_files_fail; bus_add_attrs(bus); pr_debug("bus type '%s' registered\n", bus->name); return 0; bus_probe_files_fail: kset_unregister(&bus->drivers); bus_drivers_fail: kset_unregister(&bus->devices); bus_devices_fail: subsystem_unregister(&bus->subsys); out: return retval; }
/** * 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. */ int bus_register(struct bus_type * bus) { int retval; BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier); retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name); if (retval) goto out; subsys_set_kset(bus, bus_subsys); retval = subsystem_register(&bus->subsys); if (retval) goto out; kobject_set_name(&bus->devices.kobj, "devices"); bus->devices.subsys = &bus->subsys; retval = kset_register(&bus->devices); if (retval) goto bus_devices_fail; kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.subsys = &bus->subsys; bus->drivers.ktype = &ktype_driver; retval = kset_register(&bus->drivers); if (retval) goto bus_drivers_fail; klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_drivers, NULL, NULL); retval = bus_add_attrs(bus); if (retval) goto bus_attrs_fail; pr_debug("bus type '%s' registered\n", bus->name); return 0; bus_attrs_fail: kset_unregister(&bus->drivers); bus_drivers_fail: kset_unregister(&bus->devices); bus_devices_fail: subsystem_unregister(&bus->subsys); out: return retval; }