aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2009-05-11 17:16:57 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-15 12:50:47 -0400
commitb4028437876866aba4747a655ede00f892089e14 (patch)
treef6c34315c3e6d2899a894f028bd6f9899e80cd01 /drivers/base
parent2023c610dc54a4f4130b0494309a9bd668ca3df8 (diff)
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>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/base.h5
-rw-r--r--drivers/base/core.c20
-rw-r--r--drivers/base/dd.c31
3 files changed, 48 insertions, 8 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 1e52c125f437..503d59c57501 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -70,6 +70,8 @@ struct class_private {
70 * @knode_parent - node in sibling list 70 * @knode_parent - node in sibling list
71 * @knode_driver - node in driver list 71 * @knode_driver - node in driver list
72 * @knode_bus - node in bus list 72 * @knode_bus - node in bus list
73 * @driver_data - private pointer for driver specific info. Will turn into a
74 * list soon.
73 * @device - pointer back to the struct class that this structure is 75 * @device - pointer back to the struct class that this structure is
74 * associated with. 76 * associated with.
75 * 77 *
@@ -80,6 +82,7 @@ struct device_private {
80 struct klist_node knode_parent; 82 struct klist_node knode_parent;
81 struct klist_node knode_driver; 83 struct klist_node knode_driver;
82 struct klist_node knode_bus; 84 struct klist_node knode_bus;
85 void *driver_data;
83 struct device *device; 86 struct device *device;
84}; 87};
85#define to_device_private_parent(obj) \ 88#define to_device_private_parent(obj) \
@@ -89,6 +92,8 @@ struct device_private {
89#define to_device_private_bus(obj) \ 92#define to_device_private_bus(obj) \
90 container_of(obj, struct device_private, knode_bus) 93 container_of(obj, struct device_private, knode_bus)
91 94
95extern int device_private_init(struct device *dev);
96
92/* initialisation functions */ 97/* initialisation functions */
93extern int devices_init(void); 98extern int devices_init(void);
94extern int buses_init(void); 99extern int buses_init(void);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c34774d0b9d3..99dfe96fffcb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -843,6 +843,17 @@ static void device_remove_sys_dev_entry(struct device *dev)
843 } 843 }
844} 844}
845 845
846int device_private_init(struct device *dev)
847{
848 dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
849 if (!dev->p)
850 return -ENOMEM;
851 dev->p->device = dev;
852 klist_init(&dev->p->klist_children, klist_children_get,
853 klist_children_put);
854 return 0;
855}
856
846/** 857/**
847 * device_add - add device to device hierarchy. 858 * device_add - add device to device hierarchy.
848 * @dev: device. 859 * @dev: device.
@@ -868,14 +879,11 @@ int device_add(struct device *dev)
868 if (!dev) 879 if (!dev)
869 goto done; 880 goto done;
870 881
871 dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
872 if (!dev->p) { 882 if (!dev->p) {
873 error = -ENOMEM; 883 error = device_private_init(dev);
874 goto done; 884 if (error)
885 goto done;
875 } 886 }
876 dev->p->device = dev;
877 klist_init(&dev->p->klist_children, klist_children_get,
878 klist_children_put);
879 887
880 /* 888 /*
881 * for statically allocated devices, which should all be converted 889 * for statically allocated devices, which should all be converted
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7b34b3a48f67..979d159b5cd1 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -11,8 +11,8 @@
11 * 11 *
12 * Copyright (c) 2002-5 Patrick Mochel 12 * Copyright (c) 2002-5 Patrick Mochel
13 * Copyright (c) 2002-3 Open Source Development Labs 13 * Copyright (c) 2002-3 Open Source Development Labs
14 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de> 14 * Copyright (c) 2007-2009 Greg Kroah-Hartman <gregkh@suse.de>
15 * Copyright (c) 2007 Novell Inc. 15 * Copyright (c) 2007-2009 Novell Inc.
16 * 16 *
17 * This file is released under the GPLv2 17 * This file is released under the GPLv2
18 */ 18 */
@@ -391,3 +391,30 @@ void driver_detach(struct device_driver *drv)
391 put_device(dev); 391 put_device(dev);
392 } 392 }
393} 393}
394
395/*
396 * These exports can't be _GPL due to .h files using this within them, and it
397 * might break something that was previously working...
398 */
399void *dev_get_drvdata(const struct device *dev)
400{
401 if (dev && dev->p)
402 return dev->p->driver_data;
403 return NULL;
404}
405EXPORT_SYMBOL(dev_get_drvdata);
406
407void dev_set_drvdata(struct device *dev, void *data)
408{
409 int error;
410
411 if (!dev)
412 return;
413 if (!dev->p) {
414 error = device_private_init(dev);
415 if (error)
416 return;
417 }
418 dev->p->driver_data = data;
419}
420EXPORT_SYMBOL(dev_set_drvdata);