PERFORCE change 166168 for review

Hans Petter Selasky hselasky at FreeBSD.org
Thu Jul 16 18:20:50 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=166168

Change 166168 by hselasky at hselasky_laptop001 on 2009/07/16 18:20:47

	
	USB CORE:
	 - correct return value from usbd_get_no_alts() function.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/usb_parse.c#8 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/usb_parse.c#8 (text+ko) ====

@@ -215,7 +215,9 @@
  *	usbd_get_no_alts
  *
  * Return value:
- *   Number of alternate settings for the given interface descriptor pointer.
+ *   Number of alternate settings for the given interface descriptor
+ *   pointer. If the USB descriptor is corrupt, the returned value can
+ *   be greater than the actual number of alternate settings.
  *------------------------------------------------------------------------*/
 uint8_t
 usbd_get_no_alts(struct usb_config_descriptor *cd,
@@ -225,21 +227,17 @@
 	uint8_t n;
 	uint8_t ifaceno;
 
-	/* 
-	 * We always have at least one interface setting, due to the
-	 * fact that the usb_desc_foreach() call below will skip the
-	 * first interface descriptor.
-	 */
-	n = 1;
+	/* Reset interface count */
+
+	n = 0;
 
 	/* Get the interface number */
 
 	ifaceno = id->bInterfaceNumber;
 
-	/* Get the interface descriptor */
+	/* Iterate all the USB descriptors */
 
-	desc = (struct usb_descriptor *)id;
-
+	desc = NULL;
 	while ((desc = usb_desc_foreach(cd, desc))) {
 		if ((desc->bDescriptorType == UDESC_INTERFACE) &&
 		    (desc->bLength >= sizeof(*id))) {
@@ -248,8 +246,7 @@
 				n++;
 				if (n == 0xFF)
 					break;		/* crazy */
-			} else
-				break;			/* end */
+			}
 		}
 	}
 	return (n);


More information about the p4-projects mailing list