Skip to content

Commit 11c3b5c

Browse files
committed
driver core: move klist_children into private structure
Nothing outside of the driver core should ever touch klist_children, or knode_parent, so move them out of the public eye. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 2831fe6 commit 11c3b5c

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,20 @@ struct class_private {
6666
/**
6767
* struct device_private - structure to hold the private to the driver core portions of the device structure.
6868
*
69+
* @klist_children - klist containing all children of this device
70+
* @knode_parent - node in sibling list
6971
* @device - pointer back to the struct class that this structure is
7072
* associated with.
7173
*
7274
* Nothing outside of the driver core should ever touch these fields.
7375
*/
7476
struct device_private {
77+
struct klist klist_children;
78+
struct klist_node knode_parent;
7579
struct device *device;
7680
};
81+
#define to_device_private_parent(obj) \
82+
container_of(obj, struct device_private, knode_parent)
7783

7884
/* initialisation functions */
7985
extern int devices_init(void);

‎drivers/base/core.c‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,16 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
509509

510510
static void klist_children_get(struct klist_node *n)
511511
{
512-
struct device *dev = container_of(n, struct device, knode_parent);
512+
struct device_private *p = to_device_private_parent(n);
513+
struct device *dev = p->device;
513514

514515
get_device(dev);
515516
}
516517

517518
static void klist_children_put(struct klist_node *n)
518519
{
519-
struct device *dev = container_of(n, struct device, knode_parent);
520+
struct device_private *p = to_device_private_parent(n);
521+
struct device *dev = p->device;
520522

521523
put_device(dev);
522524
}
@@ -546,7 +548,7 @@ void device_initialize(struct device *dev)
546548
dev->p->device = dev;
547549
dev->kobj.kset = devices_kset;
548550
kobject_init(&dev->kobj, &device_ktype);
549-
klist_init(&dev->klist_children, klist_children_get,
551+
klist_init(&dev->p->klist_children, klist_children_get,
550552
klist_children_put);
551553
INIT_LIST_HEAD(&dev->dma_pools);
552554
init_MUTEX(&dev->sem);
@@ -927,7 +929,8 @@ int device_add(struct device *dev)
927929
kobject_uevent(&dev->kobj, KOBJ_ADD);
928930
bus_attach_device(dev);
929931
if (parent)
930-
klist_add_tail(&dev->knode_parent, &parent->klist_children);
932+
klist_add_tail(&dev->p->knode_parent,
933+
&parent->p->klist_children);
931934

932935
if (dev->class) {
933936
mutex_lock(&dev->class->p->class_mutex);
@@ -1038,7 +1041,7 @@ void device_del(struct device *dev)
10381041
device_pm_remove(dev);
10391042
dpm_sysfs_remove(dev);
10401043
if (parent)
1041-
klist_del(&dev->knode_parent);
1044+
klist_del(&dev->p->knode_parent);
10421045
if (MAJOR(dev->devt)) {
10431046
device_remove_sys_dev_entry(dev);
10441047
device_remove_file(dev, &devt_attr);
@@ -1102,7 +1105,14 @@ void device_unregister(struct device *dev)
11021105
static struct device *next_device(struct klist_iter *i)
11031106
{
11041107
struct klist_node *n = klist_next(i);
1105-
return n ? container_of(n, struct device, knode_parent) : NULL;
1108+
struct device *dev = NULL;
1109+
struct device_private *p;
1110+
1111+
if (n) {
1112+
p = to_device_private_parent(n);
1113+
dev = p->device;
1114+
}
1115+
return dev;
11061116
}
11071117

11081118
/**
@@ -1124,7 +1134,7 @@ int device_for_each_child(struct device *parent, void *data,
11241134
struct device *child;
11251135
int error = 0;
11261136

1127-
klist_iter_init(&parent->klist_children, &i);
1137+
klist_iter_init(&parent->p->klist_children, &i);
11281138
while ((child = next_device(&i)) && !error)
11291139
error = fn(child, data);
11301140
klist_iter_exit(&i);
@@ -1155,7 +1165,7 @@ struct device *device_find_child(struct device *parent, void *data,
11551165
if (!parent)
11561166
return NULL;
11571167

1158-
klist_iter_init(&parent->klist_children, &i);
1168+
klist_iter_init(&parent->p->klist_children, &i);
11591169
while ((child = next_device(&i)))
11601170
if (match(child, data) && get_device(child))
11611171
break;
@@ -1478,9 +1488,10 @@ int device_move(struct device *dev, struct device *new_parent)
14781488
old_parent = dev->parent;
14791489
dev->parent = new_parent;
14801490
if (old_parent)
1481-
klist_remove(&dev->knode_parent);
1491+
klist_remove(&dev->p->knode_parent);
14821492
if (new_parent) {
1483-
klist_add_tail(&dev->knode_parent, &new_parent->klist_children);
1493+
klist_add_tail(&dev->p->knode_parent,
1494+
&new_parent->p->klist_children);
14841495
set_dev_node(dev, dev_to_node(new_parent));
14851496
}
14861497

@@ -1492,11 +1503,11 @@ int device_move(struct device *dev, struct device *new_parent)
14921503
device_move_class_links(dev, new_parent, old_parent);
14931504
if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
14941505
if (new_parent)
1495-
klist_remove(&dev->knode_parent);
1506+
klist_remove(&dev->p->knode_parent);
14961507
dev->parent = old_parent;
14971508
if (old_parent) {
1498-
klist_add_tail(&dev->knode_parent,
1499-
&old_parent->klist_children);
1509+
klist_add_tail(&dev->p->knode_parent,
1510+
&old_parent->p->klist_children);
15001511
set_dev_node(dev, dev_to_node(old_parent));
15011512
}
15021513
}

‎include/linux/device.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ struct device_dma_parameters {
366366
};
367367

368368
struct device {
369-
struct klist klist_children;
370-
struct klist_node knode_parent; /* node in sibling list */
371369
struct klist_node knode_driver;
372370
struct klist_node knode_bus;
373371
struct device *parent;

0 commit comments

Comments
 (0)