Driver core: move dev_get/set_drvdata to drivers/base/dd.c
No one should directly access the driver_data field, so remove the field and make it private. We dynamically create the private field now if it is needed, to handle drivers that call get/set before they are registered with the driver core. Also update the copyright notices on these files while we are there. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
@ -843,6 +843,17 @@ static void device_remove_sys_dev_entry(struct device *dev)
|
||||
}
|
||||
}
|
||||
|
||||
int device_private_init(struct device *dev)
|
||||
{
|
||||
dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
|
||||
if (!dev->p)
|
||||
return -ENOMEM;
|
||||
dev->p->device = dev;
|
||||
klist_init(&dev->p->klist_children, klist_children_get,
|
||||
klist_children_put);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* device_add - add device to device hierarchy.
|
||||
* @dev: device.
|
||||
@ -868,14 +879,11 @@ int device_add(struct device *dev)
|
||||
if (!dev)
|
||||
goto done;
|
||||
|
||||
dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
|
||||
if (!dev->p) {
|
||||
error = -ENOMEM;
|
||||
goto done;
|
||||
error = device_private_init(dev);
|
||||
if (error)
|
||||
goto done;
|
||||
}
|
||||
dev->p->device = dev;
|
||||
klist_init(&dev->p->klist_children, klist_children_get,
|
||||
klist_children_put);
|
||||
|
||||
/*
|
||||
* for statically allocated devices, which should all be converted
|
||||
|
Reference in New Issue
Block a user