aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/base/base.h5
-rw-r--r--drivers/base/core.c20
-rw-r--r--drivers/base/dd.c31
-rw-r--r--include/linux/device.h16
4 files changed, 52 insertions, 20 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);
diff --git a/include/linux/device.h b/include/linux/device.h
index a28642975053..c0bd23048be0 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -2,7 +2,8 @@
2 * device.h - generic, centralized driver model 2 * device.h - generic, centralized driver model
3 * 3 *
4 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> 4 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
5 * Copyright (c) 2004-2007 Greg Kroah-Hartman <gregkh@suse.de> 5 * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
6 * Copyright (c) 2008-2009 Novell Inc.
6 * 7 *
7 * This file is released under the GPLv2 8 * This file is released under the GPLv2
8 * 9 *
@@ -381,7 +382,6 @@ struct device {
381 struct bus_type *bus; /* type of bus device is on */ 382 struct bus_type *bus; /* type of bus device is on */
382 struct device_driver *driver; /* which driver has allocated this 383 struct device_driver *driver; /* which driver has allocated this
383 device */ 384 device */
384 void *driver_data; /* data private to the driver */
385 void *platform_data; /* Platform specific data, device 385 void *platform_data; /* Platform specific data, device
386 core doesn't touch it */ 386 core doesn't touch it */
387 struct dev_pm_info power; 387 struct dev_pm_info power;
@@ -447,16 +447,6 @@ static inline void set_dev_node(struct device *dev, int node)
447} 447}
448#endif 448#endif
449 449
450static inline void *dev_get_drvdata(const struct device *dev)
451{
452 return dev->driver_data;
453}
454
455static inline void dev_set_drvdata(struct device *dev, void *data)
456{
457 dev->driver_data = data;
458}
459
460static inline unsigned int dev_get_uevent_suppress(const struct device *dev) 450static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
461{ 451{
462 return dev->kobj.uevent_suppress; 452 return dev->kobj.uevent_suppress;
@@ -490,6 +480,8 @@ extern int device_rename(struct device *dev, char *new_name);
490extern int device_move(struct device *dev, struct device *new_parent, 480extern int device_move(struct device *dev, struct device *new_parent,
491 enum dpm_order dpm_order); 481 enum dpm_order dpm_order);
492extern const char *device_get_nodename(struct device *dev, const char **tmp); 482extern const char *device_get_nodename(struct device *dev, const char **tmp);
483extern void *dev_get_drvdata(const struct device *dev);
484extern void dev_set_drvdata(struct device *dev, void *data);
493 485
494/* 486/*
495 * Root device objects for grouping under /sys/devices 487 * Root device objects for grouping under /sys/devices