* [PATCH] driver core: add default driver attributes to struct bus_type
@ 2004-06-28 0:25 Dmitry Torokhov
2004-07-14 23:03 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2004-06-28 0:25 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
Hi Greg,
Now that we have dev_attrs in bus_type can we also add drv_attrs so devices
and drivers still have API similar to each other?
The patch also contains 2 tiny trailing whitespace fixes.
--
Dmitry
===================================================================
ChangeSet@1.1790, 2004-06-27 19:22:44-05:00, dtor_core@ameritech.net
Driver core: add default driver attributes to struct bus_type
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/base/bus.c | 37 +++++++++++++++++++++++++++++++++++--
include/linux/device.h | 1 +
2 files changed, 36 insertions(+), 2 deletions(-)
===================================================================
diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c 2004-06-27 19:24:04 -05:00
+++ b/drivers/base/bus.c 2004-06-27 19:24:04 -05:00
@@ -415,7 +415,7 @@
static void device_remove_attrs(struct bus_type * bus, struct device * dev)
{
int i;
-
+
if (bus->dev_attrs) {
for (i = 0; attr_name(bus->dev_attrs[i]); i++)
device_remove_file(dev,&bus->dev_attrs[i]);
@@ -471,6 +471,37 @@
}
}
+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.
@@ -499,6 +530,7 @@
driver_attach(drv);
up_write(&bus->subsys.rwsem);
+ driver_add_attrs(bus, drv);
}
return error;
}
@@ -516,6 +548,7 @@
void bus_remove_driver(struct device_driver * drv)
{
if (drv->bus) {
+ driver_remove_attrs(drv->bus, drv);
down_write(&drv->bus->subsys.rwsem);
pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
driver_detach(drv);
@@ -610,7 +643,7 @@
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]);
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h 2004-06-27 19:24:04 -05:00
+++ b/include/linux/device.h 2004-06-27 19:24:04 -05:00
@@ -56,6 +56,7 @@
struct bus_attribute * bus_attrs;
struct device_attribute * dev_attrs;
+ struct driver_attribute * drv_attrs;
int (*match)(struct device * dev, struct device_driver * drv);
struct device * (*add) (struct device * parent, char * bus_id);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] driver core: add default driver attributes to struct bus_type
2004-06-28 0:25 [PATCH] driver core: add default driver attributes to struct bus_type Dmitry Torokhov
@ 2004-07-14 23:03 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2004-07-14 23:03 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-kernel
On Sun, Jun 27, 2004 at 07:25:51PM -0500, Dmitry Torokhov wrote:
> Hi Greg,
>
> Now that we have dev_attrs in bus_type can we also add drv_attrs so devices
> and drivers still have API similar to each other?
>
> The patch also contains 2 tiny trailing whitespace fixes.
Applied, thanks.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-07-14 23:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-28 0:25 [PATCH] driver core: add default driver attributes to struct bus_type Dmitry Torokhov
2004-07-14 23:03 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox