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