aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorCornelia Huck <cornelia.huck@de.ibm.com>2007-12-05 06:50:23 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:34 -0500
commit57c745340a60c51d2b9af3d4dcf7e0ede284855b (patch)
tree92640edef147d32663807207c0c0604e228949e7 /drivers
parent2b937303188807b498d1a3163f60305f0941538e (diff)
driver core: Introduce default attribute groups.
This is lot like default attributes for devices (and indeed, a lot of the code is lifted from there). Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/driver.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index f94be40646d2..e3b58407fedc 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -142,6 +142,37 @@ void put_driver(struct device_driver * drv)
142 kobject_put(&drv->kobj); 142 kobject_put(&drv->kobj);
143} 143}
144 144
145static int driver_add_groups(struct device_driver *drv,
146 struct attribute_group **groups)
147{
148 int error = 0;
149 int i;
150
151 if (groups) {
152 for (i = 0; groups[i]; i++) {
153 error = sysfs_create_group(&drv->kobj, groups[i]);
154 if (error) {
155 while (--i >= 0)
156 sysfs_remove_group(&drv->kobj,
157 groups[i]);
158 break;
159 }
160 }
161 }
162 return error;
163}
164
165static void driver_remove_groups(struct device_driver *drv,
166 struct attribute_group **groups)
167{
168 int i;
169
170 if (groups)
171 for (i = 0; groups[i]; i++)
172 sysfs_remove_group(&drv->kobj, groups[i]);
173}
174
175
145/** 176/**
146 * driver_register - register driver with bus 177 * driver_register - register driver with bus
147 * @drv: driver to register 178 * @drv: driver to register
@@ -152,13 +183,21 @@ void put_driver(struct device_driver * drv)
152 */ 183 */
153int driver_register(struct device_driver * drv) 184int driver_register(struct device_driver * drv)
154{ 185{
186 int ret;
187
155 if ((drv->bus->probe && drv->probe) || 188 if ((drv->bus->probe && drv->probe) ||
156 (drv->bus->remove && drv->remove) || 189 (drv->bus->remove && drv->remove) ||
157 (drv->bus->shutdown && drv->shutdown)) { 190 (drv->bus->shutdown && drv->shutdown)) {
158 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); 191 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
159 } 192 }
160 klist_init(&drv->klist_devices, NULL, NULL); 193 klist_init(&drv->klist_devices, NULL, NULL);
161 return bus_add_driver(drv); 194 ret = bus_add_driver(drv);
195 if (ret)
196 return ret;
197 ret = driver_add_groups(drv, drv->groups);
198 if (ret)
199 bus_remove_driver(drv);
200 return ret;
162} 201}
163 202
164/** 203/**
@@ -170,6 +209,7 @@ int driver_register(struct device_driver * drv)
170 209
171void driver_unregister(struct device_driver * drv) 210void driver_unregister(struct device_driver * drv)
172{ 211{
212 driver_remove_groups(drv, drv->groups);
173 bus_remove_driver(drv); 213 bus_remove_driver(drv);
174} 214}
175 215