public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>, Kay Sievers <kay.sievers@vrfy.org>
Subject: [PATCH 02/20] Driver core: move dev_get/set_drvdata to drivers/base/dd.c
Date: Tue, 15 Sep 2009 12:12:38 -0700	[thread overview]
Message-ID: <1253041976-1111-2-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20090915181247.GA32167@kroah.com>

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>
---
 drivers/base/base.h    |    5 +++++
 drivers/base/core.c    |   20 ++++++++++++++------
 drivers/base/dd.c      |   31 +++++++++++++++++++++++++++++--
 include/linux/device.h |   16 ++++------------
 4 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 1e52c12..503d59c 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -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);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c34774d..99dfe96 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)
 	}
 }
 
+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
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7b34b3a..979d159 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -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);
diff --git a/include/linux/device.h b/include/linux/device.h
index a286429..c0bd230 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -2,7 +2,8 @@
  * device.h - generic, centralized driver model
  *
  * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
- * Copyright (c) 2004-2007 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2008-2009 Novell Inc.
  *
  * This file is released under the GPLv2
  *
@@ -381,7 +382,6 @@ struct device {
 	struct bus_type	*bus;		/* type of bus device is on */
 	struct device_driver *driver;	/* which driver has allocated this
 					   device */
-	void		*driver_data;	/* data private to the driver */
 	void		*platform_data;	/* Platform specific data, device
 					   core doesn't touch it */
 	struct dev_pm_info	power;
@@ -447,16 +447,6 @@ static inline void set_dev_node(struct device *dev, int node)
 }
 #endif
 
-static inline void *dev_get_drvdata(const struct device *dev)
-{
-	return dev->driver_data;
-}
-
-static inline void dev_set_drvdata(struct device *dev, void *data)
-{
-	dev->driver_data = data;
-}
-
 static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
 {
 	return dev->kobj.uevent_suppress;
@@ -490,6 +480,8 @@ extern int device_rename(struct device *dev, char *new_name);
 extern int device_move(struct device *dev, struct device *new_parent,
 		       enum dpm_order dpm_order);
 extern const char *device_get_nodename(struct device *dev, const char **tmp);
+extern void *dev_get_drvdata(const struct device *dev);
+extern void dev_set_drvdata(struct device *dev, void *data);
 
 /*
  * Root device objects for grouping under /sys/devices
-- 
1.6.4.2


  parent reply	other threads:[~2009-09-15 19:18 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-15 18:12 [GIT PATCH] driver core patches for 2.6.31-git Greg KH
2009-09-15 19:12 ` [PATCH 01/20] Driver core: add new device to bus's list before probing Greg Kroah-Hartman
2009-09-15 19:12 ` Greg Kroah-Hartman [this message]
2009-09-15 19:12 ` [PATCH 03/20] Driver core: Add accessor for device platform data Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 04/20] UIO: remove 'default n' from Kconfig Greg Kroah-Hartman
2009-09-15 19:35   ` Hans J. Koch
2009-09-15 19:12 ` [PATCH 05/20] driver model: constify attribute groups Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 06/20] mem_class: use minor as index instead of searching the array Greg Kroah-Hartman
2009-09-15 19:42   ` Daniel Walker
2009-09-15 19:46     ` Kay Sievers
2009-09-15 20:07       ` Daniel Walker
2009-09-15 20:24         ` Greg KH
2009-09-15 21:18           ` Daniel Walker
2009-09-15 21:20             ` Greg KH
2009-09-15 21:26               ` Daniel Walker
2009-09-15 21:32                 ` Greg KH
2009-09-15 22:06                   ` Daniel Walker
2009-09-19 15:17                 ` Tilman Schmidt
2009-09-19 16:01                   ` Daniel Walker
2009-09-15 19:12 ` [PATCH 07/20] mem_class: fix bug Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 08/20] driver-core: move dma-coherent.c from kernel to driver/base Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 09/20] uio: add generic driver for PCI 2.3 devices Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 10/20] Driver core: Add support for compatibility classes Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 11/20] driver core: platform_device_add_data(): use kmemdup() Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 12/20] hpilo: staging for interrupt handling Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 13/20] hpilo: add interrupt handler Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 14/20] hpilo: add poll f_op Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 15/20] debugfs: Fix mount directory of debugfs by default in events.txt Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 16/20] debugfs: Change debuhgfs directory of trace-events-sample.h Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 17/20] debugfs: Change debugfs directory of IWMC3200 Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 18/20] debugfs: Modified default dir of debugfs for debugging UHCI Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 19/20] debugfs: Modify default debugfs directory for debugging pktcdvd Greg Kroah-Hartman
2009-09-15 19:12 ` [PATCH 20/20] Driver Core: devtmpfs - kernel-maintained tmpfs-based /dev Greg Kroah-Hartman
2009-09-15 23:21   ` Christoph Hellwig
2009-09-15 23:43     ` Greg KH
2009-09-16 12:45 ` [GIT PATCH] driver core patches for 2.6.31-git Christoph Hellwig
2009-09-16 12:59   ` Greg KH
2009-09-16 13:15     ` Christoph Hellwig
2009-09-16 13:59       ` Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253041976-1111-2-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox