aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/core.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5d4b7e04471e..641c0c42bb48 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -197,6 +197,35 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
197 return count; 197 return count;
198} 198}
199 199
200static int device_add_groups(struct device *dev)
201{
202 int i;
203 int error = 0;
204
205 if (dev->groups) {
206 for (i = 0; dev->groups[i]; i++) {
207 error = sysfs_create_group(&dev->kobj, dev->groups[i]);
208 if (error) {
209 while (--i >= 0)
210 sysfs_remove_group(&dev->kobj, dev->groups[i]);
211 goto out;
212 }
213 }
214 }
215out:
216 return error;
217}
218
219static void device_remove_groups(struct device *dev)
220{
221 int i;
222 if (dev->groups) {
223 for (i = 0; dev->groups[i]; i++) {
224 sysfs_remove_group(&dev->kobj, dev->groups[i]);
225 }
226 }
227}
228
200static ssize_t show_dev(struct device *dev, struct device_attribute *attr, 229static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
201 char *buf) 230 char *buf)
202{ 231{
@@ -350,6 +379,8 @@ int device_add(struct device *dev)
350 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); 379 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
351 } 380 }
352 381
382 if ((error = device_add_groups(dev)))
383 goto GroupError;
353 if ((error = device_pm_add(dev))) 384 if ((error = device_pm_add(dev)))
354 goto PMError; 385 goto PMError;
355 if ((error = bus_add_device(dev))) 386 if ((error = bus_add_device(dev)))
@@ -376,6 +407,8 @@ int device_add(struct device *dev)
376 BusError: 407 BusError:
377 device_pm_remove(dev); 408 device_pm_remove(dev);
378 PMError: 409 PMError:
410 device_remove_groups(dev);
411 GroupError:
379 if (dev->devt_attr) { 412 if (dev->devt_attr) {
380 device_remove_file(dev, dev->devt_attr); 413 device_remove_file(dev, dev->devt_attr);
381 kfree(dev->devt_attr); 414 kfree(dev->devt_attr);
@@ -470,6 +503,7 @@ void device_del(struct device * dev)
470 up(&dev->class->sem); 503 up(&dev->class->sem);
471 } 504 }
472 device_remove_file(dev, &dev->uevent_attr); 505 device_remove_file(dev, &dev->uevent_attr);
506 device_remove_groups(dev);
473 507
474 /* Notify the platform of the removal, in case they 508 /* Notify the platform of the removal, in case they
475 * need to do anything... 509 * need to do anything...