
From: Dominik Brodowski <linux@dominikbrodowski.de>

Grab a reference of struct pcmcia_socket for every struct pcmcia_bus_socket.

Signed-off-by: Dominik Brodowski <linux@brodo.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/pcmcia/ds.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff -puN drivers/pcmcia/ds.c~pcmcia-grab-a-reference-to-the-cs-socket-in-ds drivers/pcmcia/ds.c
--- 25/drivers/pcmcia/ds.c~pcmcia-grab-a-reference-to-the-cs-socket-in-ds	2004-12-03 18:44:35.109445752 -0800
+++ 25-akpm/drivers/pcmcia/ds.c	2004-12-03 18:44:35.113445144 -0800
@@ -382,6 +382,7 @@ static struct pcmcia_bus_socket * get_so
 static void pcmcia_release_bus_socket(struct kref *refcount)
 {
 	struct pcmcia_bus_socket *s = container_of(refcount, struct pcmcia_bus_socket, refcount);
+	pcmcia_put_socket(s->parent);
 	kfree(s);
 }
 
@@ -1240,7 +1241,7 @@ static struct file_operations ds_fops = 
 
 static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
 {
-	struct pcmcia_socket *socket = class_dev->class_data;
+	struct pcmcia_socket *socket = class_get_devdata(class_dev);
 	struct pcmcia_bus_socket *s;
 	int ret;
 
@@ -1248,6 +1249,15 @@ static int __devinit pcmcia_bus_add_sock
 	if(!s)
 		return -ENOMEM;
 	memset(s, 0, sizeof(struct pcmcia_bus_socket));
+
+	/* get reference to parent socket */
+	s->parent = pcmcia_get_socket(socket);
+	if (!s->parent) {
+		printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
+		kfree (s);
+		return -ENODEV;
+	}
+
 	kref_init(&s->refcount);
     
 	/*
@@ -1260,9 +1270,6 @@ static int __devinit pcmcia_bus_add_sock
 	init_waitqueue_head(&s->request);
 	INIT_LIST_HEAD(&s->devices_list);
 
-	/* initialize data */
-	s->parent = socket;
-
 	/* Set up hotline to Card Services */
 	s->callback.owner = THIS_MODULE;
 	s->callback.event = &ds_event;
@@ -1282,7 +1289,7 @@ static int __devinit pcmcia_bus_add_sock
 
 static void pcmcia_bus_remove_socket(struct class_device *class_dev)
 {
-	struct pcmcia_socket *socket = class_dev->class_data;
+	struct pcmcia_socket *socket = class_get_devdata(class_dev);
 
 	if (!socket || !socket->pcmcia)
 		return;
_
