diff options
author | Tejun Heo <htejun@gmail.com> | 2007-06-13 14:45:17 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-11 19:09:06 -0400 |
commit | ad6a1e1c66009ba9dcd2f5c90ffa1fb4ce72fce0 (patch) | |
tree | 260f2a1707246998ba6f83ac1fa5a518626bbb1e /drivers/base | |
parent | 7b595756ec1f49e0049a9e01a1298d53a7faaa15 (diff) |
driver-core: make devt_attr and uevent_attr static
devt_attr and uevent_attr are either allocated dynamically with or
embedded in device and class_device as they needed their owner field
set to the module implementing the driver. Now that sysfs implements
immediate disconnect and owner field removed from struct attribute,
there is no reason to do this. Remove these attributes from
[class_]device and use static attribute structures instead.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/class.c | 44 | ||||
-rw-r--r-- | drivers/base/core.c | 45 |
2 files changed, 31 insertions, 58 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 | ||
diff --git a/drivers/base/core.c b/drivers/base/core.c index e3fb87bfc6e1..0455aa78fa13 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -310,6 +310,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | |||
310 | return count; | 310 | return count; |
311 | } | 311 | } |
312 | 312 | ||
313 | static struct device_attribute uevent_attr = | ||
314 | __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); | ||
315 | |||
313 | static int device_add_attributes(struct device *dev, | 316 | static int device_add_attributes(struct device *dev, |
314 | struct device_attribute *attrs) | 317 | struct device_attribute *attrs) |
315 | { | 318 | { |
@@ -423,6 +426,9 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr, | |||
423 | return print_dev_t(buf, dev->devt); | 426 | return print_dev_t(buf, dev->devt); |
424 | } | 427 | } |
425 | 428 | ||
429 | static struct device_attribute devt_attr = | ||
430 | __ATTR(dev, S_IRUGO, show_dev, NULL); | ||
431 | |||
426 | /* | 432 | /* |
427 | * devices_subsys - structure to be registered with kobject core. | 433 | * devices_subsys - structure to be registered with kobject core. |
428 | */ | 434 | */ |
@@ -681,31 +687,14 @@ int device_add(struct device *dev) | |||
681 | blocking_notifier_call_chain(&dev->bus->bus_notifier, | 687 | blocking_notifier_call_chain(&dev->bus->bus_notifier, |
682 | BUS_NOTIFY_ADD_DEVICE, dev); | 688 | BUS_NOTIFY_ADD_DEVICE, dev); |
683 | 689 | ||
684 | dev->uevent_attr.attr.name = "uevent"; | 690 | error = device_create_file(dev, &uevent_attr); |
685 | dev->uevent_attr.attr.mode = S_IRUGO | S_IWUSR; | ||
686 | dev->uevent_attr.store = store_uevent; | ||
687 | dev->uevent_attr.show = show_uevent; | ||
688 | error = device_create_file(dev, &dev->uevent_attr); | ||
689 | if (error) | 691 | if (error) |
690 | goto attrError; | 692 | goto attrError; |
691 | 693 | ||
692 | if (MAJOR(dev->devt)) { | 694 | if (MAJOR(dev->devt)) { |
693 | struct device_attribute *attr; | 695 | error = device_create_file(dev, &devt_attr); |
694 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | 696 | if (error) |
695 | if (!attr) { | ||
696 | error = -ENOMEM; | ||
697 | goto ueventattrError; | ||
698 | } | ||
699 | attr->attr.name = "dev"; | ||
700 | attr->attr.mode = S_IRUGO; | ||
701 | attr->show = show_dev; | ||
702 | error = device_create_file(dev, attr); | ||
703 | if (error) { | ||
704 | kfree(attr); | ||
705 | goto ueventattrError; | 697 | goto ueventattrError; |
706 | } | ||
707 | |||
708 | dev->devt_attr = attr; | ||
709 | } | 698 | } |
710 | 699 | ||
711 | if (dev->class) { | 700 | if (dev->class) { |
@@ -766,10 +755,8 @@ int device_add(struct device *dev) | |||
766 | BUS_NOTIFY_DEL_DEVICE, dev); | 755 | BUS_NOTIFY_DEL_DEVICE, dev); |
767 | device_remove_attrs(dev); | 756 | device_remove_attrs(dev); |
768 | AttrsError: | 757 | AttrsError: |
769 | if (dev->devt_attr) { | 758 | if (MAJOR(dev->devt)) |
770 | device_remove_file(dev, dev->devt_attr); | 759 | device_remove_file(dev, &devt_attr); |
771 | kfree(dev->devt_attr); | ||
772 | } | ||
773 | 760 | ||
774 | if (dev->class) { | 761 | if (dev->class) { |
775 | sysfs_remove_link(&dev->kobj, "subsystem"); | 762 | sysfs_remove_link(&dev->kobj, "subsystem"); |
@@ -791,7 +778,7 @@ int device_add(struct device *dev) | |||
791 | } | 778 | } |
792 | } | 779 | } |
793 | ueventattrError: | 780 | ueventattrError: |
794 | device_remove_file(dev, &dev->uevent_attr); | 781 | device_remove_file(dev, &uevent_attr); |
795 | attrError: | 782 | attrError: |
796 | kobject_uevent(&dev->kobj, KOBJ_REMOVE); | 783 | kobject_uevent(&dev->kobj, KOBJ_REMOVE); |
797 | kobject_del(&dev->kobj); | 784 | kobject_del(&dev->kobj); |
@@ -868,10 +855,8 @@ void device_del(struct device * dev) | |||
868 | 855 | ||
869 | if (parent) | 856 | if (parent) |
870 | klist_del(&dev->knode_parent); | 857 | klist_del(&dev->knode_parent); |
871 | if (dev->devt_attr) { | 858 | if (MAJOR(dev->devt)) |
872 | device_remove_file(dev, dev->devt_attr); | 859 | device_remove_file(dev, &devt_attr); |
873 | kfree(dev->devt_attr); | ||
874 | } | ||
875 | if (dev->class) { | 860 | if (dev->class) { |
876 | sysfs_remove_link(&dev->kobj, "subsystem"); | 861 | sysfs_remove_link(&dev->kobj, "subsystem"); |
877 | /* If this is not a "fake" compatible device, remove the | 862 | /* If this is not a "fake" compatible device, remove the |
@@ -925,7 +910,7 @@ void device_del(struct device * dev) | |||
925 | up(&dev->class->sem); | 910 | up(&dev->class->sem); |
926 | } | 911 | } |
927 | } | 912 | } |
928 | device_remove_file(dev, &dev->uevent_attr); | 913 | device_remove_file(dev, &uevent_attr); |
929 | device_remove_attrs(dev); | 914 | device_remove_attrs(dev); |
930 | bus_remove_device(dev); | 915 | bus_remove_device(dev); |
931 | 916 | ||