ChangeSet 1.1042.81.1, 2003/05/01 10:14:42-07:00, greg@kroah.com

[PATCH] USB: replace kdev_t with int in usb_interface structure, as only drivers with the USB major use it.


 drivers/usb/class/usblp.c   |    8 +++-----
 drivers/usb/core/usb.c      |   12 +++++++-----
 drivers/usb/image/scanner.c |   10 ++++------
 drivers/usb/image/scanner.h |    2 --
 drivers/usb/usb-skeleton.c  |   25 +++++--------------------
 include/linux/usb.h         |   16 ++++++++++++----
 6 files changed, 31 insertions(+), 42 deletions(-)


diff -Nru a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
--- a/drivers/usb/class/usblp.c	Wed May  7 11:13:21 2003
+++ b/drivers/usb/class/usblp.c	Wed May  7 11:13:21 2003
@@ -330,7 +330,7 @@
 	lock_kernel();
 
 	retval = -ENODEV;
-	intf = usb_find_interface(&usblp_driver, mk_kdev(USB_MAJOR,minor));
+	intf = usb_find_interface(&usblp_driver, minor);
 	if (!intf) {
 		goto out;
 	}
@@ -920,9 +920,7 @@
 		usblp->dev->descriptor.idProduct);
 
 	usb_set_intfdata (intf, usblp);
-
-	/* add device id so the device works when advertised */
-	intf->kdev = mk_kdev(USB_MAJOR,usblp->minor);
+	intf->minor = usblp->minor;
 
 	return 0;
 
@@ -1109,7 +1107,7 @@
 	struct usblp *usblp = usb_get_intfdata (intf);
 
 	/* remove device id to disable open() */
-	intf->kdev = NODEV;
+	intf->minor = -1;
 
 	if (!usblp || !usblp->dev) {
 		err("bogus disconnect");
diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c	Wed May  7 11:13:21 2003
+++ b/drivers/usb/core/usb.c	Wed May  7 11:13:21 2003
@@ -457,12 +457,13 @@
 /**
  * usb_find_interface - find usb_interface pointer for driver and device
  * @drv: the driver whose current configuration is considered
- * @kdev: the desired device
+ * @minor: the minor number of the desired device
  *
  * This walks the driver device list and returns a pointer to the interface 
- * with the matching kdev_t.
+ * with the matching minor.  Note, this only works for devices that share the
+ * USB major number.
  */
-struct usb_interface *usb_find_interface(struct usb_driver *drv, kdev_t kdev)
+struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
 {
 	struct list_head *entry;
 	struct device *dev;
@@ -476,9 +477,10 @@
 			continue;
 
 		intf = to_usb_interface(dev);
-		if (kdev_same(intf->kdev,kdev)) {
+		if (intf->minor == -1)
+			continue;
+		if (intf->minor == minor)
 			return intf;
-		}
 	}
 
 	/* no device found that matches */
diff -Nru a/drivers/usb/image/scanner.c b/drivers/usb/image/scanner.c
--- a/drivers/usb/image/scanner.c	Wed May  7 11:13:21 2003
+++ b/drivers/usb/image/scanner.c	Wed May  7 11:13:21 2003
@@ -464,7 +464,7 @@
 
 	dbg("open_scanner: scn_minor:%d", scn_minor);
 
-	intf = usb_find_interface(&scanner_driver, mk_kdev(USB_MAJOR,scn_minor));
+	intf = usb_find_interface(&scanner_driver, scn_minor);
 	if (!intf) {
 		up(&scn_mutex);
 		err("open_scanner(%d): Unable to access minor data", scn_minor);
@@ -1118,9 +1118,7 @@
 	up(&scn_mutex);
 
 	usb_set_intfdata(intf, scn);
-
-	/* add device id so the device works when advertised */
-	intf->kdev = mk_kdev(USB_MAJOR,scn->scn_minor);
+	intf->minor = scn_minor;
 
 	return 0;
 }
@@ -1130,8 +1128,8 @@
 {
 	struct scn_usb_data *scn = usb_get_intfdata(intf);
 
-	/* remove device id to disable open() */
-	intf->kdev = NODEV;
+	/* disable open() */
+	intf->minor = -1;
 
 	usb_set_intfdata(intf, NULL);
 	if(scn->intr_ep) {
diff -Nru a/drivers/usb/image/scanner.h b/drivers/usb/image/scanner.h
--- a/drivers/usb/image/scanner.h	Wed May  7 11:13:21 2003
+++ b/drivers/usb/image/scanner.h	Wed May  7 11:13:21 2003
@@ -324,10 +324,8 @@
 #define SCN_CLASS_SCANJET 16
 
 #ifdef CONFIG_USB_DYNAMIC_MINORS
-#define SCN_MAX_MNR 256
 #define SCN_BASE_MNR 0
 #else
-#define SCN_MAX_MNR 16		/* We're allocated 16 minors */
 #define SCN_BASE_MNR 48		/* USB Scanners start at minor 48 */
 #endif
 
diff -Nru a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
--- a/drivers/usb/usb-skeleton.c	Wed May  7 11:13:21 2003
+++ b/drivers/usb/usb-skeleton.c	Wed May  7 11:13:21 2003
@@ -87,12 +87,8 @@
 MODULE_DEVICE_TABLE (usb, skel_table);
 
 
-#ifdef CONFIG_USB_DYNAMIC_MINORS
-#define USB_SKEL_MINOR_BASE	0
-#else
 /* Get a minor range for your devices from the usb maintainer */
 #define USB_SKEL_MINOR_BASE	192
-#endif
 
 /* Structure to hold all of our device specific stuff */
 struct usb_skel {
@@ -153,16 +149,6 @@
 	 * This also means that the kernel can decrement
 	 * the use-counter again before calling release()
 	 * or should the open() function fail.
-	 *
-	 * Not all device structures have an "owner" field
-	 * yet. "struct file_operations" and "struct net_device"
-	 * do, while "struct tty_driver" does not. If the struct
-	 * has an "owner" field, then initialize it to the value
-	 * THIS_MODULE and the kernel will handle all module
-	 * locking for you automatically. Otherwise, you must
-	 * increment the use-counter in the open() function
-	 * and decrement it again in the release() function
-	 * yourself.
 	 */
 	.owner =	THIS_MODULE,
 
@@ -236,8 +222,7 @@
 	/* prevent disconnects */
 	down (&disconnect_sem);
 
-	interface = usb_find_interface (&skel_driver,
-					mk_kdev(USB_MAJOR, subminor));
+	interface = usb_find_interface (&skel_driver, subminor);
 	if (!interface) {
 		err ("%s - error, can't find device for minor %d",
 		     __FUNCTION__, subminor);
@@ -619,8 +604,8 @@
 	/* let the user know what node this device is now attached to */
 	info ("USB Skeleton device now attached to USBSkel-%d", dev->minor);
 
-	/* add device id so the device works when advertised */
-	interface->kdev = mk_kdev(USB_MAJOR, dev->minor);
+	/* set the minor of the interface, so open() works */
+	interface->minor = dev->minor;
 
 	goto exit;
 
@@ -667,8 +652,8 @@
 
 	down (&dev->sem);
 
-	/* remove device id to disable open() */
-	interface->kdev = NODEV;
+	/* disable open() */
+	interface->minor = -1;
 
 	minor = dev->minor;
 
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h	Wed May  7 11:13:21 2003
+++ b/include/linux/usb.h	Wed May  7 11:13:21 2003
@@ -73,12 +73,20 @@
 /**
  * struct usb_interface - what usb device drivers talk to
  * @altsetting: array of interface descriptors, one for each alternate
- * 	setting that may be selected.  each one includes a set of
- * 	endpoint configurations.
+ * 	setting that may be selected.  Each one includes a set of
+ * 	endpoint configurations and will be in numberic order,
+ * 	0..num_altsetting.
  * @num_altsetting: number of altsettings defined.
  * @act_altsetting: index of current altsetting.  this number is always
  *	less than num_altsetting.  after the device is configured, each
  *	interface uses its default setting of zero.
+ * @max_altsetting:
+ * @minor: the minor number assigned to this interface, if this
+ *	interface is bound to a driver that uses the USB major number.
+ *	If this interface does not use the USB major, this field should
+ *	be unused.  The driver should set this value in the probe()
+ *	function of the driver, after it has been assigned a minor
+ *	number from the USB core by calling usb_register_dev().
  * @dev: driver model's view of this device
  *
  * USB device drivers attach to interfaces on a physical device.  Each
@@ -111,7 +119,7 @@
 	unsigned max_altsetting;	/* total memory allocated */
 
 	struct usb_driver *driver;	/* driver */
-	kdev_t kdev;			/* node this interface is bound to */
+	int minor;			/* minor number this interface is bound to */
 	struct device dev;		/* interface specific device info */
 };
 #define	to_usb_interface(d) container_of(d, struct usb_interface, dev)
@@ -279,7 +287,7 @@
 const struct usb_device_id *usb_match_id(struct usb_interface *interface,
 					 const struct usb_device_id *id);
 
-extern struct usb_interface *usb_find_interface(struct usb_driver *drv, kdev_t kdev);
+extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor);
 extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);
 
 
