aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/core.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:17 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:06 -0400
commitad6a1e1c66009ba9dcd2f5c90ffa1fb4ce72fce0 (patch)
tree260f2a1707246998ba6f83ac1fa5a518626bbb1e /drivers/base/core.c
parent7b595756ec1f49e0049a9e01a1298d53a7faaa15 (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/core.c')
-rw-r--r--drivers/base/core.c45
1 files changed, 15 insertions, 30 deletions
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
313static struct device_attribute uevent_attr =
314 __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
315
313static int device_add_attributes(struct device *dev, 316static 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
429static 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