This is lot like default attributes for devices (and indeed,
a lot of the code is lifted from there).
Signed-off-by: Cornelia Huck <[email protected]>
---
drivers/base/driver.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
include/linux/device.h | 2 ++
2 files changed, 45 insertions(+), 1 deletion(-)
Index: linux-2.6/drivers/base/driver.c
===================================================================
--- linux-2.6.orig/drivers/base/driver.c 2007-12-05 09:53:15.000000000 +0100
+++ linux-2.6/drivers/base/driver.c 2007-12-05 12:41:02.000000000 +0100
@@ -151,6 +151,39 @@ void put_driver(struct device_driver * d
kobject_put(&drv->p->kobj);
}
+static int driver_add_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int error = 0;
+ int i;
+ struct driver_private *priv = drv->p;
+
+ if (groups) {
+ for (i = 0; groups[i]; i++) {
+ error = sysfs_create_group(&priv->kobj, groups[i]);
+ if (error) {
+ while (--i >= 0)
+ sysfs_remove_group(&priv->kobj,
+ groups[i]);
+ break;
+ }
+ }
+ }
+ return error;
+}
+
+static void driver_remove_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int i;
+ struct driver_private *priv = drv->p;
+
+ if (groups)
+ for (i = 0; groups[i]; i++)
+ sysfs_remove_group(&priv->kobj, groups[i]);
+}
+
+
/**
* driver_register - register driver with bus
* @drv: driver to register
@@ -161,12 +194,20 @@ void put_driver(struct device_driver * d
*/
int driver_register(struct device_driver * drv)
{
+ int ret;
+
if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown)) {
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
}
- return bus_add_driver(drv);
+ ret = bus_add_driver(drv);
+ if (ret)
+ return ret;
+ ret = driver_add_groups(drv, drv->groups);
+ if (ret)
+ bus_remove_driver(drv);
+ return ret;
}
/**
@@ -178,6 +219,7 @@ int driver_register(struct device_driver
void driver_unregister(struct device_driver * drv)
{
+ driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}
Index: linux-2.6/include/linux/device.h
===================================================================
--- linux-2.6.orig/include/linux/device.h 2007-12-05 09:53:15.000000000 +0100
+++ linux-2.6/include/linux/device.h 2007-12-05 12:25:36.000000000 +0100
@@ -126,6 +126,8 @@ struct device_driver {
int (*suspend) (struct device * dev, pm_message_t state);
int (*resume) (struct device * dev);
+ struct attribute_group **groups;
+
struct driver_private *p;
};
On Wed, Dec 05, 2007 at 12:50:23PM +0100, Cornelia Huck wrote:
> This is lot like default attributes for devices (and indeed,
> a lot of the code is lifted from there).
>
> Signed-off-by: Cornelia Huck <[email protected]>
>
> ---
> drivers/base/driver.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
> include/linux/device.h | 2 ++
> 2 files changed, 45 insertions(+), 1 deletion(-)
>
> Index: linux-2.6/drivers/base/driver.c
> ===================================================================
> --- linux-2.6.orig/drivers/base/driver.c 2007-12-05 09:53:15.000000000 +0100
> +++ linux-2.6/drivers/base/driver.c 2007-12-05 12:41:02.000000000 +0100
> @@ -151,6 +151,39 @@ void put_driver(struct device_driver * d
> kobject_put(&drv->p->kobj);
> }
>
> +static int driver_add_groups(struct device_driver *drv,
> + struct attribute_group **groups)
Heh, I just added a driver_add_group() function, to fix up some other
ppc driver :)
I'll delete that and use this series instead, it's nicer.
thanks,
greg k-h