<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From: Greg KH &lt;greg@kroah.com&gt;
To: torvalds@transmeta.com
Cc: linux-usb-devel@lists.sourceforge.net
Subject: [PATCH 2 of 8] USB module ownership change

Hi,

Here's a patch against 2.5.2-pre7 that allows the USB core to control
the module usage count of the USB driver modules.

thanks,

greg k-h



diff -Nru a/drivers/usb/devio.c b/drivers/usb/devio.c
--- a/drivers/usb/devio.c	Thu Jan  3 16:45:34 2002
+++ b/drivers/usb/devio.c	Thu Jan  3 16:45:34 2002
@@ -40,6 +40,7 @@
 #include &lt;linux/smp_lock.h&gt;
 #include &lt;linux/signal.h&gt;
 #include &lt;linux/poll.h&gt;
+#include &lt;linux/module.h&gt;
 #include &lt;linux/usb.h&gt;
 #include &lt;linux/usbdevice_fs.h&gt;
 #include &lt;asm/uaccess.h&gt;
@@ -1086,10 +1087,15 @@
 			else if (ifp-&gt;driver == 0 || ifp-&gt;driver-&gt;ioctl == 0)
 				retval = -ENOSYS;
 		}
-		if (retval == 0)
+		if (retval == 0) {
+			if (ifp-&gt;driver-&gt;owner)
+				__MOD_INC_USE_COUNT(ifp-&gt;driver-&gt;owner);
 			/* ifno might usefully be passed ... */
 			retval = ifp-&gt;driver-&gt;ioctl (ps-&gt;dev, ctrl.ioctl_code, buf);
 			/* size = min_t(int, size, retval)? */
+			if (ifp-&gt;driver-&gt;owner)
+				__MOD_DEC_USE_COUNT(ifp-&gt;driver-&gt;owner);
+		}
 	}
 
 	/* cleanup and return */
diff -Nru a/drivers/usb/usb.c b/drivers/usb/usb.c
--- a/drivers/usb/usb.c	Thu Jan  3 16:45:35 2002
+++ b/drivers/usb/usb.c	Thu Jan  3 16:45:35 2002
@@ -150,9 +150,13 @@
 		struct usb_interface *interface = &amp;dev-&gt;actconfig-&gt;interface[i];
 		
 		if (interface-&gt;driver == driver) {
+			if (driver-&gt;owner)
+				__MOD_INC_USE_COUNT(driver-&gt;owner);
 			down(&amp;driver-&gt;serialize);
 			driver-&gt;disconnect(dev, interface-&gt;private_data);
 			up(&amp;driver-&gt;serialize);
+			if (driver-&gt;owner)
+				__MOD_DEC_USE_COUNT(driver-&gt;owner);
 			/* if driver-&gt;disconnect didn't release the interface */
 			if (interface-&gt;driver)
 				usb_driver_release_interface(driver, interface);
@@ -781,6 +785,8 @@
 		driver = list_entry(tmp, struct usb_driver, driver_list);
 		tmp = tmp-&gt;next;
 
+		if (driver-&gt;owner)
+			__MOD_INC_USE_COUNT(driver-&gt;owner);
 		id = driver-&gt;id_table;
 		/* new style driver? */
 		if (id) {
@@ -804,6 +810,8 @@
 			private = driver-&gt;probe(dev, ifnum, NULL);
 			up(&amp;driver-&gt;serialize);
 		}
+		if (driver-&gt;owner)
+			__MOD_DEC_USE_COUNT(driver-&gt;owner);
 
 		/* probe() may have changed the config on us */
 		interface = dev-&gt;actconfig-&gt;interface + ifnum;
@@ -1887,9 +1895,13 @@
 			struct usb_interface *interface = &amp;dev-&gt;actconfig-&gt;interface[i];
 			struct usb_driver *driver = interface-&gt;driver;
 			if (driver) {
+				if (driver-&gt;owner)
+					__MOD_INC_USE_COUNT(driver-&gt;owner);
 				down(&amp;driver-&gt;serialize);
 				driver-&gt;disconnect(dev, interface-&gt;private_data);
 				up(&amp;driver-&gt;serialize);
+				if (driver-&gt;owner)
+					__MOD_DEC_USE_COUNT(driver-&gt;owner);
 				/* if driver-&gt;disconnect didn't release the interface */
 				if (interface-&gt;driver)
 					usb_driver_release_interface(driver, interface);
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h	Thu Jan  3 16:45:35 2002
+++ b/include/linux/usb.h	Thu Jan  3 16:45:35 2002
@@ -460,6 +460,7 @@
 
 /**
  * struct usb_driver - identifies USB driver to usbcore
+ * @owner: pointer to the module owner of this driver
  * @name: The driver name should be unique among USB drivers
  * @probe: Called to see if the driver is willing to manage a particular
  *	interface on a device.  The probe routine returns a handle that 
@@ -502,6 +503,7 @@
  * well as cancel any I/O requests that are still pending.
  */
 struct usb_driver {
+	struct module *owner;
 	const char *name;
 
 	void *(*probe)(
</pre></body></html>