Skip to content

Commit e54be89

Browse files
committed
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
2 parents 949f671 + c6c0ac6 commit e54be89

6 files changed

Lines changed: 70 additions & 88 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11

22
/**
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.
44
*
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
89
* @klist_devices - the klist to iterate over the @devices_kset
910
* @klist_drivers - the klist to iterate over the @drivers_kset
1011
* @bus_notifier - the bus notifier list for anything that cares about things
11-
* on this bus.
12+
* on this bus.
1213
* @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.
1422
*
1523
* 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.
1826
*/
19-
struct bus_type_private {
27+
struct subsys_private {
2028
struct kset subsys;
21-
struct kset *drivers_kset;
2229
struct kset *devices_kset;
30+
31+
struct kset *drivers_kset;
2332
struct klist klist_devices;
2433
struct klist klist_drivers;
2534
struct blocking_notifier_head bus_notifier;
2635
unsigned int drivers_autoprobe:1;
2736
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;
2842
};
43+
#define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
2944

3045
struct driver_private {
3146
struct kobject kobj;
@@ -36,33 +51,6 @@ struct driver_private {
3651
};
3752
#define to_driver(obj) container_of(obj, struct driver_private, kobj)
3853

39-
40-
/**
41-
* struct class_private - structure to hold the private to the driver core portions of the class structure.
42-
*
43-
* @class_subsys - the struct kset that defines this class. This is the main kobject
44-
* @class_devices - list of devices associated with this class
45-
* @class_interfaces - list of class_interfaces associated with this class
46-
* @class_dirs - "glue" directory for virtual devices associated with this class
47-
* @class_mutex - mutex to protect the children, devices, and interfaces lists.
48-
* @class - pointer back to the struct class that this structure is associated
49-
* with.
50-
*
51-
* This structure is the one that is the actual kobject allowing struct
52-
* class to be statically allocated safely. Nothing outside of the driver
53-
* core should ever touch these fields.
54-
*/
55-
struct class_private {
56-
struct kset class_subsys;
57-
struct klist class_devices;
58-
struct list_head class_interfaces;
59-
struct kset class_dirs;
60-
struct mutex class_mutex;
61-
struct class *class;
62-
};
63-
#define to_class(obj) \
64-
container_of(obj, struct class_private, class_subsys.kobj)
65-
6654
/**
6755
* struct device_private - structure to hold the private to the driver core portions of the device structure.
6856
*

‎drivers/base/bus.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "power/power.h"
2121

2222
#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)
2423

2524
/*
2625
* sysfs bindings for drivers
@@ -96,23 +95,23 @@ static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr,
9695
char *buf)
9796
{
9897
struct bus_attribute *bus_attr = to_bus_attr(attr);
99-
struct bus_type_private *bus_priv = to_bus(kobj);
98+
struct subsys_private *subsys_priv = to_subsys_private(kobj);
10099
ssize_t ret = 0;
101100

102101
if (bus_attr->show)
103-
ret = bus_attr->show(bus_priv->bus, buf);
102+
ret = bus_attr->show(subsys_priv->bus, buf);
104103
return ret;
105104
}
106105

107106
static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
108107
const char *buf, size_t count)
109108
{
110109
struct bus_attribute *bus_attr = to_bus_attr(attr);
111-
struct bus_type_private *bus_priv = to_bus(kobj);
110+
struct subsys_private *subsys_priv = to_subsys_private(kobj);
112111
ssize_t ret = 0;
113112

114113
if (bus_attr->store)
115-
ret = bus_attr->store(bus_priv->bus, buf, count);
114+
ret = bus_attr->store(subsys_priv->bus, buf, count);
116115
return ret;
117116
}
118117

@@ -858,9 +857,9 @@ static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
858857
int bus_register(struct bus_type *bus)
859858
{
860859
int retval;
861-
struct bus_type_private *priv;
860+
struct subsys_private *priv;
862861

863-
priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL);
862+
priv = kzalloc(sizeof(struct subsys_private), GFP_KERNEL);
864863
if (!priv)
865864
return -ENOMEM;
866865

‎drivers/base/class.c‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
2727
char *buf)
2828
{
2929
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);
3131
ssize_t ret = -EIO;
3232

3333
if (class_attr->show)
@@ -39,7 +39,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
3939
const char *buf, size_t count)
4040
{
4141
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);
4343
ssize_t ret = -EIO;
4444

4545
if (class_attr->store)
@@ -49,7 +49,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
4949

5050
static void class_release(struct kobject *kobj)
5151
{
52-
struct class_private *cp = to_class(kobj);
52+
struct subsys_private *cp = to_subsys_private(kobj);
5353
struct class *class = cp->class;
5454

5555
pr_debug("class '%s': release.\n", class->name);
@@ -65,7 +65,7 @@ static void class_release(struct kobject *kobj)
6565

6666
static const struct kobj_ns_type_operations *class_child_ns_type(struct kobject *kobj)
6767
{
68-
struct class_private *cp = to_class(kobj);
68+
struct subsys_private *cp = to_subsys_private(kobj);
6969
struct class *class = cp->class;
7070

7171
return class->ns_type;
@@ -82,15 +82,15 @@ static struct kobj_type class_ktype = {
8282
.child_ns_type = class_child_ns_type,
8383
};
8484

85-
/* Hotplug events for classes go to the class class_subsys */
85+
/* Hotplug events for classes go to the class subsys */
8686
static struct kset *class_kset;
8787

8888

8989
int class_create_file(struct class *cls, const struct class_attribute *attr)
9090
{
9191
int error;
9292
if (cls)
93-
error = sysfs_create_file(&cls->p->class_subsys.kobj,
93+
error = sysfs_create_file(&cls->p->subsys.kobj,
9494
&attr->attr);
9595
else
9696
error = -EINVAL;
@@ -100,20 +100,20 @@ int class_create_file(struct class *cls, const struct class_attribute *attr)
100100
void class_remove_file(struct class *cls, const struct class_attribute *attr)
101101
{
102102
if (cls)
103-
sysfs_remove_file(&cls->p->class_subsys.kobj, &attr->attr);
103+
sysfs_remove_file(&cls->p->subsys.kobj, &attr->attr);
104104
}
105105

106106
static struct class *class_get(struct class *cls)
107107
{
108108
if (cls)
109-
kset_get(&cls->p->class_subsys);
109+
kset_get(&cls->p->subsys);
110110
return cls;
111111
}
112112

113113
static void class_put(struct class *cls)
114114
{
115115
if (cls)
116-
kset_put(&cls->p->class_subsys);
116+
kset_put(&cls->p->subsys);
117117
}
118118

119119
static int add_class_attrs(struct class *cls)
@@ -162,19 +162,19 @@ static void klist_class_dev_put(struct klist_node *n)
162162

163163
int __class_register(struct class *cls, struct lock_class_key *key)
164164
{
165-
struct class_private *cp;
165+
struct subsys_private *cp;
166166
int error;
167167

168168
pr_debug("device class '%s': registering\n", cls->name);
169169

170170
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
171171
if (!cp)
172172
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);
174174
INIT_LIST_HEAD(&cp->class_interfaces);
175-
kset_init(&cp->class_dirs);
175+
kset_init(&cp->glue_dirs);
176176
__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);
178178
if (error) {
179179
kfree(cp);
180180
return error;
@@ -187,15 +187,15 @@ int __class_register(struct class *cls, struct lock_class_key *key)
187187
#if defined(CONFIG_BLOCK)
188188
/* let the block class directory show up in the root of sysfs */
189189
if (!sysfs_deprecated || cls != &block_class)
190-
cp->class_subsys.kobj.kset = class_kset;
190+
cp->subsys.kobj.kset = class_kset;
191191
#else
192-
cp->class_subsys.kobj.kset = class_kset;
192+
cp->subsys.kobj.kset = class_kset;
193193
#endif
194-
cp->class_subsys.kobj.ktype = &class_ktype;
194+
cp->subsys.kobj.ktype = &class_ktype;
195195
cp->class = cls;
196196
cls->p = cp;
197197

198-
error = kset_register(&cp->class_subsys);
198+
error = kset_register(&cp->subsys);
199199
if (error) {
200200
kfree(cp);
201201
return error;
@@ -210,7 +210,7 @@ void class_unregister(struct class *cls)
210210
{
211211
pr_debug("device class '%s': unregistering\n", cls->name);
212212
remove_class_attrs(cls);
213-
kset_unregister(&cls->p->class_subsys);
213+
kset_unregister(&cls->p->subsys);
214214
}
215215

216216
static void class_create_release(struct class *cls)
@@ -295,7 +295,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
295295

296296
if (start)
297297
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);
299299
iter->type = type;
300300
}
301301
EXPORT_SYMBOL_GPL(class_dev_iter_init);
@@ -482,8 +482,8 @@ void class_interface_unregister(struct class_interface *class_intf)
482482
class_put(parent);
483483
}
484484

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)
487487
{
488488
struct class_attribute_string *cs;
489489
cs = container_of(attr, struct class_attribute_string, attr);

‎drivers/base/core.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj)
647647
dir->class = class;
648648
kobject_init(&dir->kobj, &class_dir_ktype);
649649

650-
dir->kobj.kset = &class->p->class_dirs;
650+
dir->kobj.kset = &class->p->glue_dirs;
651651

652652
retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name);
653653
if (retval < 0) {
@@ -672,7 +672,7 @@ static struct kobject *get_device_parent(struct device *dev,
672672
if (sysfs_deprecated && dev->class == &block_class) {
673673
if (parent && parent->class == &block_class)
674674
return &parent->kobj;
675-
return &block_class.p->class_subsys.kobj;
675+
return &block_class.p->subsys.kobj;
676676
}
677677
#endif
678678

@@ -691,13 +691,13 @@ static struct kobject *get_device_parent(struct device *dev,
691691
mutex_lock(&gdp_mutex);
692692

693693
/* 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)
696696
if (k->parent == parent_kobj) {
697697
kobj = kobject_get(k);
698698
break;
699699
}
700-
spin_unlock(&dev->class->p->class_dirs.list_lock);
700+
spin_unlock(&dev->class->p->glue_dirs.list_lock);
701701
if (kobj) {
702702
mutex_unlock(&gdp_mutex);
703703
return kobj;
@@ -719,7 +719,7 @@ static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
719719
{
720720
/* see if we live in a "glue" directory */
721721
if (!glue_dir || !dev->class ||
722-
glue_dir->kset != &dev->class->p->class_dirs)
722+
glue_dir->kset != &dev->class->p->glue_dirs)
723723
return;
724724

725725
kobject_put(glue_dir);
@@ -746,7 +746,7 @@ static int device_add_class_symlinks(struct device *dev)
746746
return 0;
747747

748748
error = sysfs_create_link(&dev->kobj,
749-
&dev->class->p->class_subsys.kobj,
749+
&dev->class->p->subsys.kobj,
750750
"subsystem");
751751
if (error)
752752
goto out;
@@ -765,7 +765,7 @@ static int device_add_class_symlinks(struct device *dev)
765765
#endif
766766

767767
/* 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,
769769
&dev->kobj, dev_name(dev));
770770
if (error)
771771
goto out_device;
@@ -793,7 +793,7 @@ static void device_remove_class_symlinks(struct device *dev)
793793
if (sysfs_deprecated && dev->class == &block_class)
794794
return;
795795
#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));
797797
}
798798

799799
/**
@@ -984,7 +984,7 @@ int device_add(struct device *dev)
984984
mutex_lock(&dev->class->p->class_mutex);
985985
/* tie the class to the device */
986986
klist_add_tail(&dev->knode_class,
987-
&dev->class->p->class_devices);
987+
&dev->class->p->klist_devices);
988988

989989
/* notify any interfaces that the device is here */
990990
list_for_each_entry(class_intf,
@@ -1550,6 +1550,8 @@ EXPORT_SYMBOL_GPL(device_destroy);
15501550
* exclusion between two different calls of device_rename
15511551
* on the same device to ensure that new_name is valid and
15521552
* won't conflict with other devices.
1553+
*
1554+
* "Never use this function, bad things will happen" - gregkh
15531555
*/
15541556
int device_rename(struct device *dev, const char *new_name)
15551557
{
@@ -1572,7 +1574,7 @@ int device_rename(struct device *dev, const char *new_name)
15721574
}
15731575

15741576
if (dev->class) {
1575-
error = sysfs_rename_link(&dev->class->p->class_subsys.kobj,
1577+
error = sysfs_rename_link(&dev->class->p->subsys.kobj,
15761578
&dev->kobj, old_device_name, new_name);
15771579
if (error)
15781580
goto out;

0 commit comments

Comments
 (0)