Merge branch 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6

* 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6:
driver core: Document that device_rename() is only for networking
sysfs: remove useless test from sysfs_merge_group
driver-core: merge private parts of class and bus
driver core: fix whitespace in class_attr_string

+70 -88
+25 -37
drivers/base/base.h
··· 1 2 /** 3 - * struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure. 4 * 5 - * @subsys - the struct kset that defines this bus. This is the main kobject 6 - * @drivers_kset - the list of drivers associated with this bus 7 - * @devices_kset - the list of devices associated with this bus 8 * @klist_devices - the klist to iterate over the @devices_kset 9 * @klist_drivers - the klist to iterate over the @drivers_kset 10 * @bus_notifier - the bus notifier list for anything that cares about things 11 - * on this bus. 12 * @bus - pointer back to the struct bus_type that this structure is associated 13 - * with. 14 * 15 * This structure is the one that is the actual kobject allowing struct 16 - * bus_type to be statically allocated safely. Nothing outside of the driver 17 - * core should ever touch these fields. 18 */ 19 - struct bus_type_private { 20 struct kset subsys; 21 - struct kset *drivers_kset; 22 struct kset *devices_kset; 23 struct klist klist_devices; 24 struct klist klist_drivers; 25 struct blocking_notifier_head bus_notifier; 26 unsigned int drivers_autoprobe:1; 27 struct bus_type *bus; 28 }; 29 30 struct driver_private { 31 struct kobject kobj; ··· 50 struct device_driver *driver; 51 }; 52 #define to_driver(obj) container_of(obj, struct driver_private, kobj) 53 - 54 - 55 - /** 56 - * struct class_private - structure to hold the private to the driver core portions of the class structure. 57 - * 58 - * @class_subsys - the struct kset that defines this class. This is the main kobject 59 - * @class_devices - list of devices associated with this class 60 - * @class_interfaces - list of class_interfaces associated with this class 61 - * @class_dirs - "glue" directory for virtual devices associated with this class 62 - * @class_mutex - mutex to protect the children, devices, and interfaces lists. 63 - * @class - pointer back to the struct class that this structure is associated 64 - * with. 65 - * 66 - * This structure is the one that is the actual kobject allowing struct 67 - * class to be statically allocated safely. Nothing outside of the driver 68 - * core should ever touch these fields. 69 - */ 70 - struct class_private { 71 - struct kset class_subsys; 72 - struct klist class_devices; 73 - struct list_head class_interfaces; 74 - struct kset class_dirs; 75 - struct mutex class_mutex; 76 - struct class *class; 77 - }; 78 - #define to_class(obj) \ 79 - container_of(obj, struct class_private, class_subsys.kobj) 80 81 /** 82 * struct device_private - structure to hold the private to the driver core portions of the device structure.
··· 1 2 /** 3 + * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure. 4 * 5 + * @subsys - the struct kset that defines this subsystem 6 + * @devices_kset - the list of devices associated 7 + * 8 + * @drivers_kset - the list of drivers associated 9 * @klist_devices - the klist to iterate over the @devices_kset 10 * @klist_drivers - the klist to iterate over the @drivers_kset 11 * @bus_notifier - the bus notifier list for anything that cares about things 12 + * on this bus. 13 * @bus - pointer back to the struct bus_type that this structure is associated 14 + * with. 15 + * 16 + * @class_interfaces - list of class_interfaces associated 17 + * @glue_dirs - "glue" directory to put in-between the parent device to 18 + * avoid namespace conflicts 19 + * @class_mutex - mutex to protect the children, devices, and interfaces lists. 20 + * @class - pointer back to the struct class that this structure is associated 21 + * with. 22 * 23 * This structure is the one that is the actual kobject allowing struct 24 + * bus_type/class to be statically allocated safely. Nothing outside of the 25 + * driver core should ever touch these fields. 26 */ 27 + struct subsys_private { 28 struct kset subsys; 29 struct kset *devices_kset; 30 + 31 + struct kset *drivers_kset; 32 struct klist klist_devices; 33 struct klist klist_drivers; 34 struct blocking_notifier_head bus_notifier; 35 unsigned int drivers_autoprobe:1; 36 struct bus_type *bus; 37 + 38 + struct list_head class_interfaces; 39 + struct kset glue_dirs; 40 + struct mutex class_mutex; 41 + struct class *class; 42 }; 43 + #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj) 44 45 struct driver_private { 46 struct kobject kobj; ··· 35 struct device_driver *driver; 36 }; 37 #define to_driver(obj) container_of(obj, struct driver_private, kobj) 38 39 /** 40 * struct device_private - structure to hold the private to the driver core portions of the device structure.
+6 -7
drivers/base/bus.c
··· 20 #include "power/power.h" 21 22 #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) 23 - #define to_bus(obj) container_of(obj, struct bus_type_private, subsys.kobj) 24 25 /* 26 * sysfs bindings for drivers ··· 95 char *buf) 96 { 97 struct bus_attribute *bus_attr = to_bus_attr(attr); 98 - struct bus_type_private *bus_priv = to_bus(kobj); 99 ssize_t ret = 0; 100 101 if (bus_attr->show) 102 - ret = bus_attr->show(bus_priv->bus, buf); 103 return ret; 104 } 105 ··· 107 const char *buf, size_t count) 108 { 109 struct bus_attribute *bus_attr = to_bus_attr(attr); 110 - struct bus_type_private *bus_priv = to_bus(kobj); 111 ssize_t ret = 0; 112 113 if (bus_attr->store) 114 - ret = bus_attr->store(bus_priv->bus, buf, count); 115 return ret; 116 } 117 ··· 857 int bus_register(struct bus_type *bus) 858 { 859 int retval; 860 - struct bus_type_private *priv; 861 862 - priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL); 863 if (!priv) 864 return -ENOMEM; 865
··· 20 #include "power/power.h" 21 22 #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) 23 24 /* 25 * sysfs bindings for drivers ··· 96 char *buf) 97 { 98 struct bus_attribute *bus_attr = to_bus_attr(attr); 99 + struct subsys_private *subsys_priv = to_subsys_private(kobj); 100 ssize_t ret = 0; 101 102 if (bus_attr->show) 103 + ret = bus_attr->show(subsys_priv->bus, buf); 104 return ret; 105 } 106 ··· 108 const char *buf, size_t count) 109 { 110 struct bus_attribute *bus_attr = to_bus_attr(attr); 111 + struct subsys_private *subsys_priv = to_subsys_private(kobj); 112 ssize_t ret = 0; 113 114 if (bus_attr->store) 115 + ret = bus_attr->store(subsys_priv->bus, buf, count); 116 return ret; 117 } 118 ··· 858 int bus_register(struct bus_type *bus) 859 { 860 int retval; 861 + struct subsys_private *priv; 862 863 + priv = kzalloc(sizeof(struct subsys_private), GFP_KERNEL); 864 if (!priv) 865 return -ENOMEM; 866
+21 -21
drivers/base/class.c
··· 27 char *buf) 28 { 29 struct class_attribute *class_attr = to_class_attr(attr); 30 - struct class_private *cp = to_class(kobj); 31 ssize_t ret = -EIO; 32 33 if (class_attr->show) ··· 39 const char *buf, size_t count) 40 { 41 struct class_attribute *class_attr = to_class_attr(attr); 42 - struct class_private *cp = to_class(kobj); 43 ssize_t ret = -EIO; 44 45 if (class_attr->store) ··· 49 50 static void class_release(struct kobject *kobj) 51 { 52 - struct class_private *cp = to_class(kobj); 53 struct class *class = cp->class; 54 55 pr_debug("class '%s': release.\n", class->name); ··· 65 66 static const struct kobj_ns_type_operations *class_child_ns_type(struct kobject *kobj) 67 { 68 - struct class_private *cp = to_class(kobj); 69 struct class *class = cp->class; 70 71 return class->ns_type; ··· 82 .child_ns_type = class_child_ns_type, 83 }; 84 85 - /* Hotplug events for classes go to the class class_subsys */ 86 static struct kset *class_kset; 87 88 ··· 90 { 91 int error; 92 if (cls) 93 - error = sysfs_create_file(&cls->p->class_subsys.kobj, 94 &attr->attr); 95 else 96 error = -EINVAL; ··· 100 void class_remove_file(struct class *cls, const struct class_attribute *attr) 101 { 102 if (cls) 103 - sysfs_remove_file(&cls->p->class_subsys.kobj, &attr->attr); 104 } 105 106 static struct class *class_get(struct class *cls) 107 { 108 if (cls) 109 - kset_get(&cls->p->class_subsys); 110 return cls; 111 } 112 113 static void class_put(struct class *cls) 114 { 115 if (cls) 116 - kset_put(&cls->p->class_subsys); 117 } 118 119 static int add_class_attrs(struct class *cls) ··· 162 163 int __class_register(struct class *cls, struct lock_class_key *key) 164 { 165 - struct class_private *cp; 166 int error; 167 168 pr_debug("device class '%s': registering\n", cls->name); ··· 170 cp = kzalloc(sizeof(*cp), GFP_KERNEL); 171 if (!cp) 172 return -ENOMEM; 173 - klist_init(&cp->class_devices, klist_class_dev_get, klist_class_dev_put); 174 INIT_LIST_HEAD(&cp->class_interfaces); 175 - kset_init(&cp->class_dirs); 176 __mutex_init(&cp->class_mutex, "struct class mutex", key); 177 - error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name); 178 if (error) { 179 kfree(cp); 180 return error; ··· 187 #if defined(CONFIG_BLOCK) 188 /* let the block class directory show up in the root of sysfs */ 189 if (!sysfs_deprecated || cls != &block_class) 190 - cp->class_subsys.kobj.kset = class_kset; 191 #else 192 - cp->class_subsys.kobj.kset = class_kset; 193 #endif 194 - cp->class_subsys.kobj.ktype = &class_ktype; 195 cp->class = cls; 196 cls->p = cp; 197 198 - error = kset_register(&cp->class_subsys); 199 if (error) { 200 kfree(cp); 201 return error; ··· 210 { 211 pr_debug("device class '%s': unregistering\n", cls->name); 212 remove_class_attrs(cls); 213 - kset_unregister(&cls->p->class_subsys); 214 } 215 216 static void class_create_release(struct class *cls) ··· 295 296 if (start) 297 start_knode = &start->knode_class; 298 - klist_iter_init_node(&class->p->class_devices, &iter->ki, start_knode); 299 iter->type = type; 300 } 301 EXPORT_SYMBOL_GPL(class_dev_iter_init); ··· 482 class_put(parent); 483 } 484 485 - ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, 486 - char *buf) 487 { 488 struct class_attribute_string *cs; 489 cs = container_of(attr, struct class_attribute_string, attr);
··· 27 char *buf) 28 { 29 struct class_attribute *class_attr = to_class_attr(attr); 30 + struct subsys_private *cp = to_subsys_private(kobj); 31 ssize_t ret = -EIO; 32 33 if (class_attr->show) ··· 39 const char *buf, size_t count) 40 { 41 struct class_attribute *class_attr = to_class_attr(attr); 42 + struct subsys_private *cp = to_subsys_private(kobj); 43 ssize_t ret = -EIO; 44 45 if (class_attr->store) ··· 49 50 static void class_release(struct kobject *kobj) 51 { 52 + struct subsys_private *cp = to_subsys_private(kobj); 53 struct class *class = cp->class; 54 55 pr_debug("class '%s': release.\n", class->name); ··· 65 66 static const struct kobj_ns_type_operations *class_child_ns_type(struct kobject *kobj) 67 { 68 + struct subsys_private *cp = to_subsys_private(kobj); 69 struct class *class = cp->class; 70 71 return class->ns_type; ··· 82 .child_ns_type = class_child_ns_type, 83 }; 84 85 + /* Hotplug events for classes go to the class subsys */ 86 static struct kset *class_kset; 87 88 ··· 90 { 91 int error; 92 if (cls) 93 + error = sysfs_create_file(&cls->p->subsys.kobj, 94 &attr->attr); 95 else 96 error = -EINVAL; ··· 100 void class_remove_file(struct class *cls, const struct class_attribute *attr) 101 { 102 if (cls) 103 + sysfs_remove_file(&cls->p->subsys.kobj, &attr->attr); 104 } 105 106 static struct class *class_get(struct class *cls) 107 { 108 if (cls) 109 + kset_get(&cls->p->subsys); 110 return cls; 111 } 112 113 static void class_put(struct class *cls) 114 { 115 if (cls) 116 + kset_put(&cls->p->subsys); 117 } 118 119 static int add_class_attrs(struct class *cls) ··· 162 163 int __class_register(struct class *cls, struct lock_class_key *key) 164 { 165 + struct subsys_private *cp; 166 int error; 167 168 pr_debug("device class '%s': registering\n", cls->name); ··· 170 cp = kzalloc(sizeof(*cp), GFP_KERNEL); 171 if (!cp) 172 return -ENOMEM; 173 + klist_init(&cp->klist_devices, klist_class_dev_get, klist_class_dev_put); 174 INIT_LIST_HEAD(&cp->class_interfaces); 175 + kset_init(&cp->glue_dirs); 176 __mutex_init(&cp->class_mutex, "struct class mutex", key); 177 + error = kobject_set_name(&cp->subsys.kobj, "%s", cls->name); 178 if (error) { 179 kfree(cp); 180 return error; ··· 187 #if defined(CONFIG_BLOCK) 188 /* let the block class directory show up in the root of sysfs */ 189 if (!sysfs_deprecated || cls != &block_class) 190 + cp->subsys.kobj.kset = class_kset; 191 #else 192 + cp->subsys.kobj.kset = class_kset; 193 #endif 194 + cp->subsys.kobj.ktype = &class_ktype; 195 cp->class = cls; 196 cls->p = cp; 197 198 + error = kset_register(&cp->subsys); 199 if (error) { 200 kfree(cp); 201 return error; ··· 210 { 211 pr_debug("device class '%s': unregistering\n", cls->name); 212 remove_class_attrs(cls); 213 + kset_unregister(&cls->p->subsys); 214 } 215 216 static void class_create_release(struct class *cls) ··· 295 296 if (start) 297 start_knode = &start->knode_class; 298 + klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode); 299 iter->type = type; 300 } 301 EXPORT_SYMBOL_GPL(class_dev_iter_init); ··· 482 class_put(parent); 483 } 484 485 + ssize_t show_class_attr_string(struct class *class, 486 + struct class_attribute *attr, char *buf) 487 { 488 struct class_attribute_string *cs; 489 cs = container_of(attr, struct class_attribute_string, attr);
+13 -11
drivers/base/core.c
··· 647 dir->class = class; 648 kobject_init(&dir->kobj, &class_dir_ktype); 649 650 - dir->kobj.kset = &class->p->class_dirs; 651 652 retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); 653 if (retval < 0) { ··· 672 if (sysfs_deprecated && dev->class == &block_class) { 673 if (parent && parent->class == &block_class) 674 return &parent->kobj; 675 - return &block_class.p->class_subsys.kobj; 676 } 677 #endif 678 ··· 691 mutex_lock(&gdp_mutex); 692 693 /* find our class-directory at the parent and reference it */ 694 - spin_lock(&dev->class->p->class_dirs.list_lock); 695 - list_for_each_entry(k, &dev->class->p->class_dirs.list, entry) 696 if (k->parent == parent_kobj) { 697 kobj = kobject_get(k); 698 break; 699 } 700 - spin_unlock(&dev->class->p->class_dirs.list_lock); 701 if (kobj) { 702 mutex_unlock(&gdp_mutex); 703 return kobj; ··· 719 { 720 /* see if we live in a "glue" directory */ 721 if (!glue_dir || !dev->class || 722 - glue_dir->kset != &dev->class->p->class_dirs) 723 return; 724 725 kobject_put(glue_dir); ··· 746 return 0; 747 748 error = sysfs_create_link(&dev->kobj, 749 - &dev->class->p->class_subsys.kobj, 750 "subsystem"); 751 if (error) 752 goto out; ··· 765 #endif 766 767 /* link in the class directory pointing to the device */ 768 - error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 769 &dev->kobj, dev_name(dev)); 770 if (error) 771 goto out_device; ··· 793 if (sysfs_deprecated && dev->class == &block_class) 794 return; 795 #endif 796 - sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); 797 } 798 799 /** ··· 984 mutex_lock(&dev->class->p->class_mutex); 985 /* tie the class to the device */ 986 klist_add_tail(&dev->knode_class, 987 - &dev->class->p->class_devices); 988 989 /* notify any interfaces that the device is here */ 990 list_for_each_entry(class_intf, ··· 1550 * exclusion between two different calls of device_rename 1551 * on the same device to ensure that new_name is valid and 1552 * won't conflict with other devices. 1553 */ 1554 int device_rename(struct device *dev, const char *new_name) 1555 { ··· 1574 } 1575 1576 if (dev->class) { 1577 - error = sysfs_rename_link(&dev->class->p->class_subsys.kobj, 1578 &dev->kobj, old_device_name, new_name); 1579 if (error) 1580 goto out;
··· 647 dir->class = class; 648 kobject_init(&dir->kobj, &class_dir_ktype); 649 650 + dir->kobj.kset = &class->p->glue_dirs; 651 652 retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); 653 if (retval < 0) { ··· 672 if (sysfs_deprecated && dev->class == &block_class) { 673 if (parent && parent->class == &block_class) 674 return &parent->kobj; 675 + return &block_class.p->subsys.kobj; 676 } 677 #endif 678 ··· 691 mutex_lock(&gdp_mutex); 692 693 /* find our class-directory at the parent and reference it */ 694 + spin_lock(&dev->class->p->glue_dirs.list_lock); 695 + list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry) 696 if (k->parent == parent_kobj) { 697 kobj = kobject_get(k); 698 break; 699 } 700 + spin_unlock(&dev->class->p->glue_dirs.list_lock); 701 if (kobj) { 702 mutex_unlock(&gdp_mutex); 703 return kobj; ··· 719 { 720 /* see if we live in a "glue" directory */ 721 if (!glue_dir || !dev->class || 722 + glue_dir->kset != &dev->class->p->glue_dirs) 723 return; 724 725 kobject_put(glue_dir); ··· 746 return 0; 747 748 error = sysfs_create_link(&dev->kobj, 749 + &dev->class->p->subsys.kobj, 750 "subsystem"); 751 if (error) 752 goto out; ··· 765 #endif 766 767 /* link in the class directory pointing to the device */ 768 + error = sysfs_create_link(&dev->class->p->subsys.kobj, 769 &dev->kobj, dev_name(dev)); 770 if (error) 771 goto out_device; ··· 793 if (sysfs_deprecated && dev->class == &block_class) 794 return; 795 #endif 796 + sysfs_delete_link(&dev->class->p->subsys.kobj, &dev->kobj, dev_name(dev)); 797 } 798 799 /** ··· 984 mutex_lock(&dev->class->p->class_mutex); 985 /* tie the class to the device */ 986 klist_add_tail(&dev->knode_class, 987 + &dev->class->p->klist_devices); 988 989 /* notify any interfaces that the device is here */ 990 list_for_each_entry(class_intf, ··· 1550 * exclusion between two different calls of device_rename 1551 * on the same device to ensure that new_name is valid and 1552 * won't conflict with other devices. 1553 + * 1554 + * "Never use this function, bad things will happen" - gregkh 1555 */ 1556 int device_rename(struct device *dev, const char *new_name) 1557 { ··· 1572 } 1573 1574 if (dev->class) { 1575 + error = sysfs_rename_link(&dev->class->p->subsys.kobj, 1576 &dev->kobj, old_device_name, new_name); 1577 if (error) 1578 goto out;
+2 -8
fs/sysfs/group.c
··· 165 struct attribute *const *attr; 166 int i; 167 168 - if (grp) 169 - dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name); 170 - else 171 - dir_sd = sysfs_get(kobj->sd); 172 if (!dir_sd) 173 return -ENOENT; 174 ··· 192 struct sysfs_dirent *dir_sd; 193 struct attribute *const *attr; 194 195 - if (grp) 196 - dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name); 197 - else 198 - dir_sd = sysfs_get(kobj->sd); 199 if (dir_sd) { 200 for (attr = grp->attrs; *attr; ++attr) 201 sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
··· 165 struct attribute *const *attr; 166 int i; 167 168 + dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name); 169 if (!dir_sd) 170 return -ENOENT; 171 ··· 195 struct sysfs_dirent *dir_sd; 196 struct attribute *const *attr; 197 198 + dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name); 199 if (dir_sd) { 200 for (attr = grp->attrs; *attr; ++attr) 201 sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
+3 -4
include/linux/device.h
··· 30 struct device_driver; 31 struct driver_private; 32 struct class; 33 - struct class_private; 34 struct bus_type; 35 - struct bus_type_private; 36 struct device_node; 37 38 struct bus_attribute { ··· 64 65 const struct dev_pm_ops *pm; 66 67 - struct bus_type_private *p; 68 }; 69 70 extern int __must_check bus_register(struct bus_type *bus); ··· 213 214 const struct dev_pm_ops *pm; 215 216 - struct class_private *p; 217 }; 218 219 struct class_dev_iter {
··· 30 struct device_driver; 31 struct driver_private; 32 struct class; 33 + struct subsys_private; 34 struct bus_type; 35 struct device_node; 36 37 struct bus_attribute { ··· 65 66 const struct dev_pm_ops *pm; 67 68 + struct subsys_private *p; 69 }; 70 71 extern int __must_check bus_register(struct bus_type *bus); ··· 214 215 const struct dev_pm_ops *pm; 216 217 + struct subsys_private *p; 218 }; 219 220 struct class_dev_iter {