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:
Greg Kroah-Hartman
2009-05-11 14:16:57 -07:00
parent 2023c610dc
commit b402843787
4 changed files with 52 additions and 20 deletions

View File

@ -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