mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
parent
2023c610dc
commit
b402843787
4 changed files with 52 additions and 20 deletions
|
|
@ -70,6 +70,8 @@ struct class_private {
|
|||
* @knode_parent - node in sibling list
|
||||
* @knode_driver - node in driver list
|
||||
* @knode_bus - node in bus list
|
||||
* @driver_data - private pointer for driver specific info. Will turn into a
|
||||
* list soon.
|
||||
* @device - pointer back to the struct class that this structure is
|
||||
* associated with.
|
||||
*
|
||||
|
|
@ -80,6 +82,7 @@ struct device_private {
|
|||
struct klist_node knode_parent;
|
||||
struct klist_node knode_driver;
|
||||
struct klist_node knode_bus;
|
||||
void *driver_data;
|
||||
struct device *device;
|
||||
};
|
||||
#define to_device_private_parent(obj) \
|
||||
|
|
@ -89,6 +92,8 @@ struct device_private {
|
|||
#define to_device_private_bus(obj) \
|
||||
container_of(obj, struct device_private, knode_bus)
|
||||
|
||||
extern int device_private_init(struct device *dev);
|
||||
|
||||
/* initialisation functions */
|
||||
extern int devices_init(void);
|
||||
extern int buses_init(void);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
*
|
||||
* Copyright (c) 2002-5 Patrick Mochel
|
||||
* Copyright (c) 2002-3 Open Source Development Labs
|
||||
* Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
|
||||
* Copyright (c) 2007 Novell Inc.
|
||||
* Copyright (c) 2007-2009 Greg Kroah-Hartman <gregkh@suse.de>
|
||||
* Copyright (c) 2007-2009 Novell Inc.
|
||||
*
|
||||
* This file is released under the GPLv2
|
||||
*/
|
||||
|
|
@ -391,3 +391,30 @@ void driver_detach(struct device_driver *drv)
|
|||
put_device(dev);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* These exports can't be _GPL due to .h files using this within them, and it
|
||||
* might break something that was previously working...
|
||||
*/
|
||||
void *dev_get_drvdata(const struct device *dev)
|
||||
{
|
||||
if (dev && dev->p)
|
||||
return dev->p->driver_data;
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(dev_get_drvdata);
|
||||
|
||||
void dev_set_drvdata(struct device *dev, void *data)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (!dev)
|
||||
return;
|
||||
if (!dev->p) {
|
||||
error = device_private_init(dev);
|
||||
if (error)
|
||||
return;
|
||||
}
|
||||
dev->p->driver_data = data;
|
||||
}
|
||||
EXPORT_SYMBOL(dev_set_drvdata);
|
||||
|
|
|
|||
Loading…
Reference in a new issue