Commit ee831b82 authored by Patrick Mochel's avatar Patrick Mochel

[Driver Model] Add default attributes for struct bus_type.

- Similar to default attributes for struct class, this is an array
  of attributes, terminated with an attribute with a NULL name, that
  are added when the bus is registered, and removed when the bus is 
  unregistered. 
parent 0d1c76a0
...@@ -549,6 +549,41 @@ struct bus_type * find_bus(char * name) ...@@ -549,6 +549,41 @@ struct bus_type * find_bus(char * name)
return k ? to_bus(k) : NULL; return k ? to_bus(k) : NULL;
} }
/**
* 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)
{
int error = 0;
int i;
if (bus->bus_attrs) {
for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
goto Err;
}
}
Done:
return error;
Err:
while (i >= 0)
bus_remove_file(bus,&bus->bus_attrs[i]);
goto Done;
}
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_register - register a bus with the system. * bus_register - register a bus with the system.
* @bus: bus. * @bus: bus.
...@@ -582,6 +617,7 @@ int bus_register(struct bus_type * bus) ...@@ -582,6 +617,7 @@ int bus_register(struct bus_type * bus)
retval = kset_register(&bus->drivers); retval = kset_register(&bus->drivers);
if (retval) if (retval)
goto bus_drivers_fail; goto bus_drivers_fail;
bus_add_attrs(bus);
pr_debug("bus type '%s' registered\n",bus->name); pr_debug("bus type '%s' registered\n",bus->name);
return 0; return 0;
...@@ -605,6 +641,7 @@ int bus_register(struct bus_type * bus) ...@@ -605,6 +641,7 @@ int bus_register(struct bus_type * bus)
void bus_unregister(struct bus_type * bus) void bus_unregister(struct bus_type * bus)
{ {
pr_debug("bus %s: unregistering\n",bus->name); pr_debug("bus %s: unregistering\n",bus->name);
bus_remove_attrs(bus);
kset_unregister(&bus->drivers); kset_unregister(&bus->drivers);
kset_unregister(&bus->devices); kset_unregister(&bus->devices);
subsystem_unregister(&bus->subsys); subsystem_unregister(&bus->subsys);
......
...@@ -54,6 +54,8 @@ struct bus_type { ...@@ -54,6 +54,8 @@ struct bus_type {
struct kset drivers; struct kset drivers;
struct kset devices; struct kset devices;
struct bus_attribute * bus_attrs;
int (*match)(struct device * dev, struct device_driver * drv); int (*match)(struct device * dev, struct device_driver * drv);
struct device * (*add) (struct device * parent, char * bus_id); struct device * (*add) (struct device * parent, char * bus_id);
int (*hotplug) (struct device *dev, char **envp, int (*hotplug) (struct device *dev, char **envp,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment