[PCMCIA][3/3] use driver_find

Dominik Brodowski linux at dominikbrodowski.de
Fri Oct 22 15:58:44 EDT 2004


Use driver_find() in ds.c instead of legacy implementation, and make use of
its reference counting awareness.

Signed-off-by: Dominik Brodowski <linux at dominikbrodowski.de>

diff -ruN linux-original/drivers/pcmcia/ds.c linux/drivers/pcmcia/ds.c
--- linux-original/drivers/pcmcia/ds.c	2004-10-22 16:38:43.000000000 +0200
+++ linux/drivers/pcmcia/ds.c	2004-10-22 21:24:52.179203784 +0200
@@ -565,9 +565,14 @@
 	       (char *)bind_info->dev_info);
 
 	p_drv = get_pcmcia_driver(&bind_info->dev_info);
-	if ((!p_drv) || (!try_module_get(p_drv->owner)))
+	if (!p_drv)
 		return -EINVAL;
 
+	if (!try_module_get(p_drv->owner)) {
+		put_driver(&p_drv->drv);
+		return -EINVAL;
+	}
+
 	/* Currently, the userspace pcmcia cardmgr detects pcmcia devices. 
 	 * Here this information is translated into a kernel
 	 * struct pcmcia_device.
@@ -630,13 +635,19 @@
 			goto err_unregister;
 		}
 	}
-    
+
+	put_driver(&p_drv->drv); /* we can safely put the reference we got
+				  * in get_pcmcia_device here, as the device
+				  * got added in between and holds a reference
+				  * for us. */
+
 	return 0;
 
  err_unregister:
 	device_unregister(&p_dev->dev);
  err_put:
 	module_put(p_drv->owner);
+	put_driver(&p_drv->drv);
 	return (ret);
 } /* bind_request */
 
@@ -1412,33 +1423,18 @@
 
 /* backwards-compatible accessing of driver --- by name! */
 
-struct cmp_data {
-	void *dev_info;
-	struct pcmcia_driver *drv;
-};
-
-static int cmp_drv_callback(struct device_driver *drv, void *data)
-{
-	struct cmp_data *cmp = data;
-	if (strncmp((char *)cmp->dev_info, (char *)drv->name,
-		    DEV_NAME_LEN) == 0) {
-		cmp->drv = container_of(drv, struct pcmcia_driver, drv);
-		return -EINVAL;
-	}
-	return 0;
-}
-
 static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
 {
-	int ret;
-	struct cmp_data cmp = {
-		.dev_info = dev_info,
-	};
-	
-	ret = bus_for_each_drv(&pcmcia_bus_type, NULL, &cmp, cmp_drv_callback);
-	if (ret)
-		return cmp.drv;
-	return NULL;
+	struct device_driver *drv;
+	struct pcmcia_driver *p_drv;
+
+	drv = driver_find((char *) dev_info, &pcmcia_bus_type);
+	if (!drv)
+		return NULL;
+
+	p_drv = container_of(drv, struct pcmcia_driver, drv);
+
+	return (p_drv);
 }
 
 MODULE_ALIAS("ds");



More information about the linux-pcmcia mailing list