speedtch Makefile, 1.12, 1.13 cxacru2.c, 1.3, 1.4 usbatm.h, 1.5, 1.6 usbatm2.c, 1.15, 1.16

Roman Kagan rkagan at mail.ru
Tue Feb 1 08:52:01 EST 2005


  Hi Duncan,

FWIW here's a patch to the current CVS removing all the subdriver
registration and making the subdriver's probe pass the pointer to struct
usbatm_driver to the core.  Aren't you impressed by the diff stats:

 cxacru.c |   21 +++++++--------------
 usbatm.c |   45 ++-------------------------------------------
 usbatm.h |   10 ++--------
 3 files changed, 11 insertions(+), 65 deletions(-)

(I didn't touch the speedtouch - not enough speed :)

And this way it becomes free from the deficiency inherited from
usb-serial, where multiple subdrivers matching the same usb_device_id
would ruin the registration stuff.

Cheers,
  Roman.

Index: usbatm.c
===================================================================
RCS file: /home/cvs/usbatm/usbatm.c,v
retrieving revision 1.3
diff -u -r1.3 usbatm.c
--- usbatm.c	28 Jan 2005 23:55:40 -0000	1.3
+++ usbatm.c	1 Feb 2005 13:39:58 -0000
@@ -202,12 +202,6 @@
 };
 
 
-/* mini drivers */
-
-static DECLARE_MUTEX(usbatm_driver_sem);
-static LIST_HEAD(usbatm_driver_list);
-
-
 /***********
 **  misc  **
 ***********/
@@ -1034,10 +1028,10 @@
 	return 0;
 }
 
-int usbatm_usb_probe (struct usb_interface *intf, const struct usb_device_id *id)
+int usbatm_usb_probe (struct usb_interface *intf, const struct usb_device_id *id,
+		struct usbatm_driver *driver)
 {
 	struct usb_device *dev = interface_to_usbdev(intf);
-	struct usbatm_driver *driver = NULL, *candidate;
 	struct usbatm_data *instance;
 	char *buf;
 	int error = -ENOMEM;
@@ -1047,19 +1041,6 @@
 
 	dev_dbg(&intf->dev, "trying device with vendor=0x%x, product=0x%x, ifnum %d\n", dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum);
 
-	down(&usbatm_driver_sem);
-	list_for_each_entry(candidate, &usbatm_driver_list, driver_list)
-		if (usb_match_id(intf, candidate->id_table)) {
-			driver = candidate;
-			break;
-		}
-	up(&usbatm_driver_sem);
-
-	if (!driver) {
-		dev_dbg(&intf->dev, "no matching usbatm driver!\n");
-		return -ENODEV;
-	}
-
 	/* instance init */
 	if (!(instance = kmalloc(sizeof(*instance), GFP_KERNEL))) {
 		dev_dbg(&intf->dev, "no memory for instance data!\n");
@@ -1297,28 +1278,6 @@
 **  init  **
 ***********/
 
-int usbatm_register (struct usbatm_driver *driver)
-{
-	dbg("registering usbatm driver %s", driver->driver_name);
-
-	down(&usbatm_driver_sem);
-	list_add(&driver->driver_list, &usbatm_driver_list);
-	up(&usbatm_driver_sem);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(usbatm_register);
-
-void usbatm_deregister (struct usbatm_driver *driver)
-{
-	dbg("deregistering usbatm driver %s", driver->driver_name);
-
-	down(&usbatm_driver_sem);
-	list_del(&driver->driver_list);
-	up(&usbatm_driver_sem);
-}
-EXPORT_SYMBOL_GPL(usbatm_deregister);
-
 static int __init usbatm_usb_init(void)
 {
 	dbg("usbatm_usb_init: driver version " DRIVER_VERSION);
Index: usbatm.h
===================================================================
RCS file: /home/cvs/usbatm/usbatm.h,v
retrieving revision 1.7
diff -u -r1.7 usbatm.h
--- usbatm.h	28 Jan 2005 23:51:52 -0000	1.7
+++ usbatm.h	1 Feb 2005 13:39:58 -0000
@@ -64,7 +64,6 @@
 	struct module *owner;
 
 	const char *driver_name;
-	const struct usb_device_id *id_table;
 
 	/*
 	*  init device ... can sleep, or cause probe() failure.  Drivers with a heavy_init
@@ -89,15 +88,10 @@
 
 	unsigned rx_padding;
 	unsigned tx_padding;
-
-	/* private */
-	struct list_head driver_list;
 };
 
-extern int usbatm_register(struct usbatm_driver *driver);
-extern void usbatm_deregister(struct usbatm_driver *driver);
-
-extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id);
+extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
+		struct usbatm_driver *driver);
 extern void usbatm_usb_disconnect(struct usb_interface *intf);
 
 
Index: cxacru.c
===================================================================
RCS file: /home/cvs/usbatm/cxacru.c,v
retrieving revision 1.7
diff -u -r1.7 cxacru.c
--- cxacru.c	28 Jan 2005 23:55:40 -0000	1.7
+++ cxacru.c	1 Feb 2005 13:39:58 -0000
@@ -825,7 +825,6 @@
 static struct usbatm_driver cxacru_driver = {
 	.owner		= THIS_MODULE,
 	.driver_name	= cxacru_driver_name,
-	.id_table	= cxacru_usb_ids,
 	.bind		= cxacru_bind,
 	.heavy_init	= cxacru_heavy_init,
 	.unbind		= cxacru_unbind,
@@ -836,33 +835,27 @@
 	.tx_padding	= 11,
 };
 
+static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+	return usbatm_usb_probe(intf, id, &cxacru_driver);
+}
+
 static struct usb_driver cxacru_usb_driver = {
 	.owner		= THIS_MODULE,
 	.name		= cxacru_driver_name,
-	.probe		= usbatm_usb_probe,
+	.probe		= cxacru_usb_probe,
 	.disconnect	= usbatm_usb_disconnect,
 	.id_table	= cxacru_usb_ids
 };
 
 static int __init cxacru_init(void)
 {
-	int ret;
-
-	if ((ret = usbatm_register(&cxacru_driver)))
-		return ret;
-
-	if ((ret = usb_register(&cxacru_usb_driver))) {
-		usbatm_deregister(&cxacru_driver);
-		return ret;
-	}
-
-	return 0;
+	return usb_register(&cxacru_usb_driver);
 }
 
 static void __exit cxacru_cleanup(void)
 {
 	usb_deregister(&cxacru_usb_driver);
-	usbatm_deregister(&cxacru_driver);
 }
 
 module_init(cxacru_init);



More information about the Usbatm mailing list