diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2006-05-06 20:55:11 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-05-06 20:55:11 -0400 |
commit | 1498221d51a43d5fa1a580618591497d90f957d9 (patch) | |
tree | 20554a3fa474c9d09f649958b85b90a3de718477 /drivers/base | |
parent | 5528e568a760442e0ec8fd2dea1f0791875a066b (diff) |
[CLASS DEVICE]: add attribute_group creation
Extend the support of attribute groups in class_device's to allow
groups to be created as part of the registration process. This allows
network device's to avoid race between registration and creating
groups.
Note that unlike attributes that are a property of the class object,
the groups are a property of the class_device object. This is done
because there are different types of network devices (wireless for
example).
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/class.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 0e71dff327cd..b1ea4df85c7d 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -456,6 +456,35 @@ static void class_device_remove_attrs(struct class_device * cd) | |||
456 | } | 456 | } |
457 | } | 457 | } |
458 | 458 | ||
459 | static int class_device_add_groups(struct class_device * cd) | ||
460 | { | ||
461 | int i; | ||
462 | int error = 0; | ||
463 | |||
464 | if (cd->groups) { | ||
465 | for (i = 0; cd->groups[i]; i++) { | ||
466 | error = sysfs_create_group(&cd->kobj, cd->groups[i]); | ||
467 | if (error) { | ||
468 | while (--i >= 0) | ||
469 | sysfs_remove_group(&cd->kobj, cd->groups[i]); | ||
470 | goto out; | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | out: | ||
475 | return error; | ||
476 | } | ||
477 | |||
478 | static void class_device_remove_groups(struct class_device * cd) | ||
479 | { | ||
480 | int i; | ||
481 | if (cd->groups) { | ||
482 | for (i = 0; cd->groups[i]; i++) { | ||
483 | sysfs_remove_group(&cd->kobj, cd->groups[i]); | ||
484 | } | ||
485 | } | ||
486 | } | ||
487 | |||
459 | static ssize_t show_dev(struct class_device *class_dev, char *buf) | 488 | static ssize_t show_dev(struct class_device *class_dev, char *buf) |
460 | { | 489 | { |
461 | return print_dev_t(buf, class_dev->devt); | 490 | return print_dev_t(buf, class_dev->devt); |
@@ -559,6 +588,8 @@ int class_device_add(struct class_device *class_dev) | |||
559 | class_name); | 588 | class_name); |
560 | } | 589 | } |
561 | 590 | ||
591 | class_device_add_groups(class_dev); | ||
592 | |||
562 | kobject_uevent(&class_dev->kobj, KOBJ_ADD); | 593 | kobject_uevent(&class_dev->kobj, KOBJ_ADD); |
563 | 594 | ||
564 | /* notify any interfaces this device is now here */ | 595 | /* notify any interfaces this device is now here */ |
@@ -672,6 +703,7 @@ void class_device_del(struct class_device *class_dev) | |||
672 | if (class_dev->devt_attr) | 703 | if (class_dev->devt_attr) |
673 | class_device_remove_file(class_dev, class_dev->devt_attr); | 704 | class_device_remove_file(class_dev, class_dev->devt_attr); |
674 | class_device_remove_attrs(class_dev); | 705 | class_device_remove_attrs(class_dev); |
706 | class_device_remove_groups(class_dev); | ||
675 | 707 | ||
676 | kobject_uevent(&class_dev->kobj, KOBJ_REMOVE); | 708 | kobject_uevent(&class_dev->kobj, KOBJ_REMOVE); |
677 | kobject_del(&class_dev->kobj); | 709 | kobject_del(&class_dev->kobj); |