
From: Dominik Brodowski <linux@dominikbrodowski.net>

Move the removal of a device from a driver (a.k.a.  "detach") to a
driver-model conform pcmcia_device_remove() function which is called within
device_unregister().

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

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

diff -puN drivers/pcmcia/ds.c~pcmcia-pcmcia_device_remove drivers/pcmcia/ds.c
--- 25/drivers/pcmcia/ds.c~pcmcia-pcmcia_device_remove	Sun Mar  6 17:28:03 2005
+++ 25-akpm/drivers/pcmcia/ds.c	Sun Mar  6 17:28:03 2005
@@ -286,6 +286,7 @@ static struct pcmcia_bus_socket *pcmcia_
  * Registers a PCMCIA driver with the PCMCIA bus core.
  */
 static int pcmcia_device_probe(struct device *dev);
+static int pcmcia_device_remove(struct device * dev);
 
 int pcmcia_register_driver(struct pcmcia_driver *driver)
 {
@@ -296,6 +297,7 @@ int pcmcia_register_driver(struct pcmcia
 	driver->drv.bus = &pcmcia_bus_type;
 	driver->drv.owner = driver->owner;
 	driver->drv.probe = pcmcia_device_probe;
+	driver->drv.remove = pcmcia_device_remove;
 
 	return driver_register(&driver->drv);
 }
@@ -404,6 +406,28 @@ static int pcmcia_device_probe(struct de
 }
 
 
+static int pcmcia_device_remove(struct device * dev)
+{
+	struct pcmcia_device *p_dev;
+	struct pcmcia_driver *p_drv;
+
+	/* detach the "instance" */
+	p_dev = to_pcmcia_dev(dev);
+	p_drv = to_pcmcia_drv(dev->driver);
+
+	if (p_drv) {
+		if ((p_drv->detach) && (p_dev->instance)) {
+			p_drv->detach(p_dev->instance);
+			/* from pcmcia_probe_device */
+			put_device(&p_dev->dev);
+		}
+		module_put(p_drv->owner);
+	}
+
+	return 0;
+}
+
+
 /*======================================================================
 
     These manage a ring buffer of events pending for one user process
@@ -866,7 +890,6 @@ static int get_device_info(struct pcmcia
 static int unbind_request(struct pcmcia_bus_socket *s)
 {
 	struct pcmcia_device	*p_dev;
-	struct pcmcia_driver	*p_drv;
 	unsigned long		flags;
 
 	ds_dbg(2, "unbind_request(%d)\n", s->parent->sock);
@@ -885,17 +908,6 @@ static int unbind_request(struct pcmcia_
 		p_dev->client.state |= CLIENT_STALE;
 		spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 
-		/* detach the "instance" */
-		p_drv = to_pcmcia_drv(p_dev->dev.driver);
-		if (p_drv) {
-			if ((p_drv->detach) && (p_dev->instance)) {
-				p_drv->detach(p_dev->instance);
-				/* from pcmcia_probe_device */
-				put_device(&p_dev->dev);
-			}
-			module_put(p_drv->owner);
-		}
-
 		device_unregister(&p_dev->dev);
 	}
 
_
