diff options
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 9cbfde23b9e3..4d2222618b78 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -312,9 +312,6 @@ static void class_dev_release(struct kobject * kobj) | |||
312 | 312 | ||
313 | pr_debug("device class '%s': release.\n", cd->class_id); | 313 | pr_debug("device class '%s': release.\n", cd->class_id); |
314 | 314 | ||
315 | kfree(cd->devt_attr); | ||
316 | cd->devt_attr = NULL; | ||
317 | |||
318 | if (cd->release) | 315 | if (cd->release) |
319 | cd->release(cd); | 316 | cd->release(cd); |
320 | else if (cls->release) | 317 | else if (cls->release) |
@@ -547,6 +544,9 @@ static ssize_t show_dev(struct class_device *class_dev, char *buf) | |||
547 | return print_dev_t(buf, class_dev->devt); | 544 | return print_dev_t(buf, class_dev->devt); |
548 | } | 545 | } |
549 | 546 | ||
547 | static struct class_device_attribute class_devt_attr = | ||
548 | __ATTR(dev, S_IRUGO, show_dev, NULL); | ||
549 | |||
550 | static ssize_t store_uevent(struct class_device *class_dev, | 550 | static ssize_t store_uevent(struct class_device *class_dev, |
551 | const char *buf, size_t count) | 551 | const char *buf, size_t count) |
552 | { | 552 | { |
@@ -554,6 +554,9 @@ static ssize_t store_uevent(struct class_device *class_dev, | |||
554 | return count; | 554 | return count; |
555 | } | 555 | } |
556 | 556 | ||
557 | static struct class_device_attribute class_uevent_attr = | ||
558 | __ATTR(uevent, S_IWUSR, NULL, store_uevent); | ||
559 | |||
557 | void class_device_initialize(struct class_device *class_dev) | 560 | void class_device_initialize(struct class_device *class_dev) |
558 | { | 561 | { |
559 | kobj_set_kset_s(class_dev, class_obj_subsys); | 562 | kobj_set_kset_s(class_dev, class_obj_subsys); |
@@ -603,30 +606,15 @@ int class_device_add(struct class_device *class_dev) | |||
603 | &parent_class->subsys.kobj, "subsystem"); | 606 | &parent_class->subsys.kobj, "subsystem"); |
604 | if (error) | 607 | if (error) |
605 | goto out3; | 608 | goto out3; |
606 | class_dev->uevent_attr.attr.name = "uevent"; | 609 | |
607 | class_dev->uevent_attr.attr.mode = S_IWUSR; | 610 | error = class_device_create_file(class_dev, &class_uevent_attr); |
608 | class_dev->uevent_attr.store = store_uevent; | ||
609 | error = class_device_create_file(class_dev, &class_dev->uevent_attr); | ||
610 | if (error) | 611 | if (error) |
611 | goto out3; | 612 | goto out3; |
612 | 613 | ||
613 | if (MAJOR(class_dev->devt)) { | 614 | if (MAJOR(class_dev->devt)) { |
614 | struct class_device_attribute *attr; | 615 | error = class_device_create_file(class_dev, &class_devt_attr); |
615 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | 616 | if (error) |
616 | if (!attr) { | ||
617 | error = -ENOMEM; | ||
618 | goto out4; | ||
619 | } | ||
620 | attr->attr.name = "dev"; | ||
621 | attr->attr.mode = S_IRUGO; | ||
622 | attr->show = show_dev; | ||
623 | error = class_device_create_file(class_dev, attr); | ||
624 | if (error) { | ||
625 | kfree(attr); | ||
626 | goto out4; | 617 | goto out4; |
627 | } | ||
628 | |||
629 | class_dev->devt_attr = attr; | ||
630 | } | 618 | } |
631 | 619 | ||
632 | error = class_device_add_attrs(class_dev); | 620 | error = class_device_add_attrs(class_dev); |
@@ -669,10 +657,10 @@ int class_device_add(struct class_device *class_dev) | |||
669 | out6: | 657 | out6: |
670 | class_device_remove_attrs(class_dev); | 658 | class_device_remove_attrs(class_dev); |
671 | out5: | 659 | out5: |
672 | if (class_dev->devt_attr) | 660 | if (MAJOR(class_dev->devt)) |
673 | class_device_remove_file(class_dev, class_dev->devt_attr); | 661 | class_device_remove_file(class_dev, &class_devt_attr); |
674 | out4: | 662 | out4: |
675 | class_device_remove_file(class_dev, &class_dev->uevent_attr); | 663 | class_device_remove_file(class_dev, &class_uevent_attr); |
676 | out3: | 664 | out3: |
677 | kobject_del(&class_dev->kobj); | 665 | kobject_del(&class_dev->kobj); |
678 | out2: | 666 | out2: |
@@ -772,9 +760,9 @@ void class_device_del(struct class_device *class_dev) | |||
772 | sysfs_remove_link(&class_dev->kobj, "device"); | 760 | sysfs_remove_link(&class_dev->kobj, "device"); |
773 | } | 761 | } |
774 | sysfs_remove_link(&class_dev->kobj, "subsystem"); | 762 | sysfs_remove_link(&class_dev->kobj, "subsystem"); |
775 | class_device_remove_file(class_dev, &class_dev->uevent_attr); | 763 | class_device_remove_file(class_dev, &class_uevent_attr); |
776 | if (class_dev->devt_attr) | 764 | if (MAJOR(class_dev->devt)) |
777 | class_device_remove_file(class_dev, class_dev->devt_attr); | 765 | class_device_remove_file(class_dev, &class_devt_attr); |
778 | class_device_remove_attrs(class_dev); | 766 | class_device_remove_attrs(class_dev); |
779 | class_device_remove_groups(class_dev); | 767 | class_device_remove_groups(class_dev); |
780 | 768 | ||