Skip to content

Commit 570d020

Browse files
Wei Yanggregkh
authored andcommitted
driver core: move device->knode_class to device_private
As the description of struct device_private says, it stores data which is private to driver core. And it already has similar fields like: knode_parent, knode_driver, knode_driver and knode_bus. This look it is more proper to put knode_class together with those fields to make it private to driver core. This patch move device->knode_class to device_private to make it comply with code convention. Signed-off-by: Wei Yang <richardw.yang@linux.intel.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4bd4e92 commit 570d020

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct driver_private {
6060
* @knode_parent - node in sibling list
6161
* @knode_driver - node in driver list
6262
* @knode_bus - node in bus list
63+
* @knode_class - node in class list
6364
* @deferred_probe - entry in deferred_probe_list which is used to retry the
6465
* binding of drivers which were unable to get all the resources needed by
6566
* the device; typically because it depends on another driver getting
@@ -74,6 +75,7 @@ struct device_private {
7475
struct klist_node knode_parent;
7576
struct klist_node knode_driver;
7677
struct klist_node knode_bus;
78+
struct klist_node knode_class;
7779
struct list_head deferred_probe;
7880
struct device *device;
7981
};
@@ -83,6 +85,8 @@ struct device_private {
8385
container_of(obj, struct device_private, knode_driver)
8486
#define to_device_private_bus(obj) \
8587
container_of(obj, struct device_private, knode_bus)
88+
#define to_device_private_class(obj) \
89+
container_of(obj, struct device_private, knode_class)
8690

8791
/* initialisation functions */
8892
extern int devices_init(void);

‎drivers/base/class.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ static void class_put(struct class *cls)
117117
kset_put(&cls->p->subsys);
118118
}
119119

120+
static struct device *klist_class_to_dev(struct klist_node *n)
121+
{
122+
struct device_private *p = to_device_private_class(n);
123+
return p->device;
124+
}
125+
120126
static void klist_class_dev_get(struct klist_node *n)
121127
{
122-
struct device *dev = container_of(n, struct device, knode_class);
128+
struct device *dev = klist_class_to_dev(n);
123129

124130
get_device(dev);
125131
}
126132

127133
static void klist_class_dev_put(struct klist_node *n)
128134
{
129-
struct device *dev = container_of(n, struct device, knode_class);
135+
struct device *dev = klist_class_to_dev(n);
130136

131137
put_device(dev);
132138
}
@@ -277,7 +283,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
277283
struct klist_node *start_knode = NULL;
278284

279285
if (start)
280-
start_knode = &start->knode_class;
286+
start_knode = &start->p->knode_class;
281287
klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode);
282288
iter->type = type;
283289
}
@@ -304,7 +310,7 @@ struct device *class_dev_iter_next(struct class_dev_iter *iter)
304310
knode = klist_next(&iter->ki);
305311
if (!knode)
306312
return NULL;
307-
dev = container_of(knode, struct device, knode_class);
313+
dev = klist_class_to_dev(knode);
308314
if (!iter->type || iter->type == dev->type)
309315
return dev;
310316
}

‎drivers/base/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ int device_add(struct device *dev)
19661966
if (dev->class) {
19671967
mutex_lock(&dev->class->p->mutex);
19681968
/* tie the class to the device */
1969-
klist_add_tail(&dev->knode_class,
1969+
klist_add_tail(&dev->p->knode_class,
19701970
&dev->class->p->klist_devices);
19711971

19721972
/* notify any interfaces that the device is here */
@@ -2105,7 +2105,7 @@ void device_del(struct device *dev)
21052105
if (class_intf->remove_dev)
21062106
class_intf->remove_dev(dev, class_intf);
21072107
/* remove the device from the class list */
2108-
klist_del(&dev->knode_class);
2108+
klist_del(&dev->p->knode_class);
21092109
mutex_unlock(&dev->class->p->mutex);
21102110
}
21112111
device_remove_file(dev, &dev_attr_uevent);

‎include/linux/device.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,6 @@ struct device {
10351035
spinlock_t devres_lock;
10361036
struct list_head devres_head;
10371037

1038-
struct klist_node knode_class;
10391038
struct class *class;
10401039
const struct attribute_group **groups; /* optional groups */
10411040

0 commit comments

Comments
 (0)