Commit 8f855b02 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman

[PATCH] Driver core: add default driver attributes to struct bus_type

Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 5966c837
...@@ -415,7 +415,7 @@ static int device_add_attrs(struct bus_type * bus, struct device * dev) ...@@ -415,7 +415,7 @@ static int device_add_attrs(struct bus_type * bus, struct device * dev)
static void device_remove_attrs(struct bus_type * bus, struct device * dev) static void device_remove_attrs(struct bus_type * bus, struct device * dev)
{ {
int i; int i;
if (bus->dev_attrs) { if (bus->dev_attrs) {
for (i = 0; attr_name(bus->dev_attrs[i]); i++) for (i = 0; attr_name(bus->dev_attrs[i]); i++)
device_remove_file(dev,&bus->dev_attrs[i]); device_remove_file(dev,&bus->dev_attrs[i]);
...@@ -471,6 +471,37 @@ void bus_remove_device(struct device * dev) ...@@ -471,6 +471,37 @@ void bus_remove_device(struct device * dev)
} }
} }
static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
{
int error = 0;
int i;
if (bus->drv_attrs) {
for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
error = driver_create_file(drv, &bus->drv_attrs[i]);
if (error)
goto Err;
}
}
Done:
return error;
Err:
while (--i >= 0)
driver_remove_file(drv, &bus->drv_attrs[i]);
goto Done;
}
static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
{
int i;
if (bus->drv_attrs) {
for (i = 0; attr_name(bus->drv_attrs[i]); i++)
driver_remove_file(drv, &bus->drv_attrs[i]);
}
}
/** /**
* bus_add_driver - Add a driver to the bus. * bus_add_driver - Add a driver to the bus.
...@@ -499,6 +530,7 @@ int bus_add_driver(struct device_driver * drv) ...@@ -499,6 +530,7 @@ int bus_add_driver(struct device_driver * drv)
driver_attach(drv); driver_attach(drv);
up_write(&bus->subsys.rwsem); up_write(&bus->subsys.rwsem);
driver_add_attrs(bus, drv);
} }
return error; return error;
} }
...@@ -516,6 +548,7 @@ int bus_add_driver(struct device_driver * drv) ...@@ -516,6 +548,7 @@ int bus_add_driver(struct device_driver * drv)
void bus_remove_driver(struct device_driver * drv) void bus_remove_driver(struct device_driver * drv)
{ {
if (drv->bus) { if (drv->bus) {
driver_remove_attrs(drv->bus, drv);
down_write(&drv->bus->subsys.rwsem); down_write(&drv->bus->subsys.rwsem);
pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
driver_detach(drv); driver_detach(drv);
...@@ -610,7 +643,7 @@ static int bus_add_attrs(struct bus_type * bus) ...@@ -610,7 +643,7 @@ static int bus_add_attrs(struct bus_type * bus)
static void bus_remove_attrs(struct bus_type * bus) static void bus_remove_attrs(struct bus_type * bus)
{ {
int i; int i;
if (bus->bus_attrs) { if (bus->bus_attrs) {
for (i = 0; attr_name(bus->bus_attrs[i]); i++) for (i = 0; attr_name(bus->bus_attrs[i]); i++)
bus_remove_file(bus,&bus->bus_attrs[i]); bus_remove_file(bus,&bus->bus_attrs[i]);
......
...@@ -56,6 +56,7 @@ struct bus_type { ...@@ -56,6 +56,7 @@ struct bus_type {
struct bus_attribute * bus_attrs; struct bus_attribute * bus_attrs;
struct device_attribute * dev_attrs; struct device_attribute * dev_attrs;
struct driver_attribute * drv_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);
......
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