aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r--drivers/base/class.c46
1 files changed, 16 insertions, 30 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8c506dbe3913..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
547static struct class_device_attribute class_devt_attr =
548 __ATTR(dev, S_IRUGO, show_dev, NULL);
549
550static ssize_t store_uevent(struct class_device *class_dev, 550static 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
557static struct class_device_attribute class_uevent_attr =
558 __ATTR(uevent, S_IWUSR, NULL, store_uevent);
559
557void class_device_initialize(struct class_device *class_dev) 560void 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,32 +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.attr.owner = parent_class->owner;
609 class_dev->uevent_attr.store = store_uevent;
610 error = class_device_create_file(class_dev, &class_dev->uevent_attr);
611 if (error) 611 if (error)
612 goto out3; 612 goto out3;
613 613
614 if (MAJOR(class_dev->devt)) { 614 if (MAJOR(class_dev->devt)) {
615 struct class_device_attribute *attr; 615 error = class_device_create_file(class_dev, &class_devt_attr);
616 attr = kzalloc(sizeof(*attr), GFP_KERNEL); 616 if (error)
617 if (!attr) {
618 error = -ENOMEM;
619 goto out4;
620 }
621 attr->attr.name = "dev";
622 attr->attr.mode = S_IRUGO;
623 attr->attr.owner = parent_class->owner;
624 attr->show = show_dev;
625 error = class_device_create_file(class_dev, attr);
626 if (error) {
627 kfree(attr);
628 goto out4; 617 goto out4;
629 }
630
631 class_dev->devt_attr = attr;
632 } 618 }
633 619
634 error = class_device_add_attrs(class_dev); 620 error = class_device_add_attrs(class_dev);
@@ -671,10 +657,10 @@ int class_device_add(struct class_device *class_dev)
671 out6: 657 out6:
672 class_device_remove_attrs(class_dev); 658 class_device_remove_attrs(class_dev);
673 out5: 659 out5:
674 if (class_dev->devt_attr) 660 if (MAJOR(class_dev->devt))
675 class_device_remove_file(class_dev, class_dev->devt_attr); 661 class_device_remove_file(class_dev, &class_devt_attr);
676 out4: 662 out4:
677 class_device_remove_file(class_dev, &class_dev->uevent_attr); 663 class_device_remove_file(class_dev, &class_uevent_attr);
678 out3: 664 out3:
679 kobject_del(&class_dev->kobj); 665 kobject_del(&class_dev->kobj);
680 out2: 666 out2:
@@ -774,9 +760,9 @@ void class_device_del(struct class_device *class_dev)
774 sysfs_remove_link(&class_dev->kobj, "device"); 760 sysfs_remove_link(&class_dev->kobj, "device");
775 } 761 }
776 sysfs_remove_link(&class_dev->kobj, "subsystem"); 762 sysfs_remove_link(&class_dev->kobj, "subsystem");
777 class_device_remove_file(class_dev, &class_dev->uevent_attr); 763 class_device_remove_file(class_dev, &class_uevent_attr);
778 if (class_dev->devt_attr) 764 if (MAJOR(class_dev->devt))
779 class_device_remove_file(class_dev, class_dev->devt_attr); 765 class_device_remove_file(class_dev, &class_devt_attr);
780 class_device_remove_attrs(class_dev); 766 class_device_remove_attrs(class_dev);
781 class_device_remove_groups(class_dev); 767 class_device_remove_groups(class_dev);
782 768