Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 May 2009 23:12:02 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r192938 - head/sys/dev/usb
Message-ID:  <200905272312.n4RNC2Nb015070@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Wed May 27 23:12:02 2009
New Revision: 192938
URL: http://svn.freebsd.org/changeset/base/192938

Log:
  Allocate the usb serial, manufacturer and product strings rather than use char
  arrays in the usb_device struct. This also eliminates USB_HAVE_STRINGS.

Modified:
  head/sys/dev/usb/usb_core.h
  head/sys/dev/usb/usb_device.c
  head/sys/dev/usb/usb_device.h
  head/sys/dev/usb/usb_generic.c
  head/sys/dev/usb/usb_hub.c
  head/sys/dev/usb/usb_util.c

Modified: head/sys/dev/usb/usb_core.h
==============================================================================
--- head/sys/dev/usb/usb_core.h	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_core.h	Wed May 27 23:12:02 2009	(r192938)
@@ -57,14 +57,6 @@
 #endif
 
 /*
- * The following macro defines if the code shall support any forms of
- * ASCII strings.
- */
-#ifndef USB_HAVE_STRINGS
-#define	USB_HAVE_STRINGS 1
-#endif
-
-/*
  * The following macro defines if the code shall support BUS-DMA.
  */
 #ifndef USB_HAVE_BUSDMA

Modified: head/sys/dev/usb/usb_device.c
==============================================================================
--- head/sys/dev/usb/usb_device.c	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_device.c	Wed May 27 23:12:02 2009	(r192938)
@@ -71,9 +71,7 @@ static void	usb2_suspend_resume_sub(stru
 		    uint8_t);
 static void	usb2_clear_stall_proc(struct usb2_proc_msg *_pm);
 usb2_error_t	usb2_config_parse(struct usb2_device *, uint8_t, uint8_t);
-#if USB_HAVE_STRINGS
-static void	usb2_check_strings(struct usb2_device *);
-#endif
+static void	usb2_set_device_strings(struct usb2_device *);
 #if USB_HAVE_UGEN
 static void	usb2_notify_addq(const char *type, struct usb2_device *);
 static void	usb2_fifo_free_wrap(struct usb2_device *, uint8_t, uint8_t);
@@ -1676,32 +1674,8 @@ usb2_alloc_device(device_t parent_dev, s
 
 	/* assume 100mA bus powered for now. Changed when configured. */
 	udev->power = USB_MIN_POWER;
-
-#if USB_HAVE_STRINGS
-	/* get serial number string */
-	err = usb2_req_get_string_any
-	    (udev, NULL, (char *)scratch_ptr,
-	    scratch_size, udev->ddesc.iSerialNumber);
-
-	strlcpy(udev->serial, (char *)scratch_ptr, sizeof(udev->serial));
-
-	/* get manufacturer string */
-	err = usb2_req_get_string_any
-	    (udev, NULL, (char *)scratch_ptr,
-	    scratch_size, udev->ddesc.iManufacturer);
-
-	strlcpy(udev->manufacturer, (char *)scratch_ptr, sizeof(udev->manufacturer));
-
-	/* get product string */
-	err = usb2_req_get_string_any
-	    (udev, NULL, (char *)scratch_ptr,
-	    scratch_size, udev->ddesc.iProduct);
-
-	strlcpy(udev->product, (char *)scratch_ptr, sizeof(udev->product));
-
-	/* finish up all the strings */
-	usb2_check_strings(udev);
-#endif
+	/* fetch the vendor and product strings from the device */
+	usb2_set_device_strings(udev);
 
 	if (udev->flags.usb_mode == USB_MODE_HOST) {
 		uint8_t config_index;
@@ -2113,11 +2087,7 @@ usb2_devinfo(struct usb2_device *udev, c
 	if (udd->bDeviceClass != 0xFF) {
 		snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/"
 		    "%x.%02x, addr %d",
-#if USB_HAVE_STRINGS
 		    udev->manufacturer, udev->product,
-#else
-		    "-", "-",
-#endif
 		    udd->bDeviceClass, udd->bDeviceSubClass,
 		    (bcdUSB >> 8), bcdUSB & 0xFF,
 		    (bcdDevice >> 8), bcdDevice & 0xFF,
@@ -2125,18 +2095,13 @@ usb2_devinfo(struct usb2_device *udev, c
 	} else {
 		snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/"
 		    "%x.%02x, addr %d",
-#if USB_HAVE_STRINGS
 		    udev->manufacturer, udev->product,
-#else
-		    "-", "-",
-#endif
 		    (bcdUSB >> 8), bcdUSB & 0xFF,
 		    (bcdDevice >> 8), bcdDevice & 0xFF,
 		    udev->address);
 	}
 }
 
-#if USB_HAVE_STRINGS
 #if USB_VERBOSE
 /*
  * Descriptions of of known vendors and devices ("products").
@@ -2155,85 +2120,74 @@ struct usb_knowndev {
 #include "usbdevs_data.h"
 #endif					/* USB_VERBOSE */
 
-/*------------------------------------------------------------------------*
- *	usb2_check_strings
- *
- * This function checks the manufacturer and product strings and will
- * fill in defaults for missing strings.
- *------------------------------------------------------------------------*/
 static void
-usb2_check_strings(struct usb2_device *udev)
+usb2_set_device_strings(struct usb2_device *udev)
 {
 	struct usb2_device_descriptor *udd = &udev->ddesc;
-	const char *vendor;
-	const char *product;
-
 #if USB_VERBOSE
 	const struct usb_knowndev *kdp;
-
 #endif
+	char temp[64];
 	uint16_t vendor_id;
 	uint16_t product_id;
 
-	usb2_trim_spaces(udev->manufacturer);
-	usb2_trim_spaces(udev->product);
+	vendor_id = UGETW(udd->idVendor);
+	product_id = UGETW(udd->idProduct);
 
-	if (udev->manufacturer[0]) {
-		vendor = udev->manufacturer;
-	} else {
-		vendor = NULL;
-	}
+	/* get serial number string */
+	bzero(temp, sizeof(temp));
+	usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
+	    udev->ddesc.iSerialNumber);
+	udev->serial = strdup(temp, M_USB);
 
-	if (udev->product[0]) {
-		product = udev->product;
-	} else {
-		product = NULL;
-	}
+	/* get manufacturer string */
+	bzero(temp, sizeof(temp));
+	usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
+	    udev->ddesc.iManufacturer);
+	usb2_trim_spaces(temp);
+	if (temp[0] != '\0')
+		udev->manufacturer = strdup(temp, M_USB);
 
-	vendor_id = UGETW(udd->idVendor);
-	product_id = UGETW(udd->idProduct);
+	/* get product string */
+	bzero(temp, sizeof(temp));
+	usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
+	    udev->ddesc.iProduct);
+	usb2_trim_spaces(temp);
+	if (temp[0] != '\0')
+		udev->product = strdup(temp, M_USB);
 
 #if USB_VERBOSE
-	if (vendor == NULL || product == NULL) {
-
-		for (kdp = usb_knowndevs;
-		    kdp->vendorname != NULL;
-		    kdp++) {
+	if (udev->manufacturer == NULL || udev->product == NULL) {
+		for (kdp = usb_knowndevs; kdp->vendorname != NULL; kdp++) {
 			if (kdp->vendor == vendor_id &&
 			    (kdp->product == product_id ||
 			    (kdp->flags & USB_KNOWNDEV_NOPROD) != 0))
 				break;
 		}
 		if (kdp->vendorname != NULL) {
-			if (vendor == NULL)
-				vendor = kdp->vendorname;
-			if (product == NULL)
-				product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ?
-				    kdp->productname : NULL;
+			/* XXX should use pointer to knowndevs string */
+			if (udev->manufacturer == NULL) {
+				udev->manufacturer = strdup(kdp->vendorname,
+				    M_USB);
+			}
+			if (udev->product == NULL &&
+			    (kdp->flags & USB_KNOWNDEV_NOPROD) == 0) {
+				udev->product = strdup(kdp->productname,
+				    M_USB);
+			}
 		}
 	}
 #endif
-	if (vendor && *vendor) {
-		if (udev->manufacturer != vendor) {
-			strlcpy(udev->manufacturer, vendor,
-			    sizeof(udev->manufacturer));
-		}
-	} else {
-		snprintf(udev->manufacturer,
-		    sizeof(udev->manufacturer), "vendor 0x%04x", vendor_id);
-	}
-
-	if (product && *product) {
-		if (udev->product != product) {
-			strlcpy(udev->product, product,
-			    sizeof(udev->product));
-		}
-	} else {
-		snprintf(udev->product,
-		    sizeof(udev->product), "product 0x%04x", product_id);
+	/* Provide default strings if none were found */
+	if (udev->manufacturer == NULL) {
+		snprintf(temp, sizeof(temp), "vendor 0x%04x", vendor_id);
+		udev->manufacturer = strdup(temp, M_USB);
+	}
+	if (udev->product == NULL) {
+		snprintf(temp, sizeof(temp), "product 0x%04x", product_id);
+		udev->product = strdup(temp, M_USB);
 	}
 }
-#endif
 
 /*
  * Returns:
@@ -2367,11 +2321,7 @@ usb2_notify_addq(const char *type, struc
 	    UGETW(udev->ddesc.idProduct),
 	    udev->ddesc.bDeviceClass,
 	    udev->ddesc.bDeviceSubClass,
-#if USB_HAVE_STRINGS
 	    udev->serial,
-#else
-	    "",
-#endif
 	    udev->port_no,
 	    udev->parent_hub != NULL ?
 		udev->parent_hub->ugen_name :

Modified: head/sys/dev/usb/usb_device.h
==============================================================================
--- head/sys/dev/usb/usb_device.h	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_device.h	Wed May 27 23:12:02 2009	(r192938)
@@ -174,11 +174,9 @@ struct usb2_device {
 	struct usb2_endpoint_descriptor default_ep_desc;	/* for pipe 0 */
 	struct usb2_device_descriptor ddesc;	/* device descriptor */
 
-#if USB_HAVE_STRINGS
-	char	serial[64];		/* serial number */
-	char	manufacturer[64];	/* manufacturer string */
-	char	product[64];		/* product string */
-#endif
+	char	*serial;		/* serial number */
+	char	*manufacturer;		/* manufacturer string */
+	char	*product;		/* product string */
 };
 
 /* globals */

Modified: head/sys/dev/usb/usb_generic.c
==============================================================================
--- head/sys/dev/usb/usb_generic.c	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_generic.c	Wed May 27 23:12:02 2009	(r192938)
@@ -801,14 +801,9 @@ usb2_gen_fill_deviceinfo(struct usb2_fif
 	di->udi_bus = device_get_unit(udev->bus->bdev);
 	di->udi_addr = udev->address;
 	di->udi_index = udev->device_index;
-#if USB_HAVE_STRINGS
-	strlcpy(di->udi_serial, udev->serial,
-	    sizeof(di->udi_serial));
-	strlcpy(di->udi_vendor, udev->manufacturer,
-	    sizeof(di->udi_vendor));
-	strlcpy(di->udi_product, udev->product,
-	    sizeof(di->udi_product));
-#endif
+	strlcpy(di->udi_serial, udev->serial, sizeof(di->udi_serial));
+	strlcpy(di->udi_vendor, udev->manufacturer, sizeof(di->udi_vendor));
+	strlcpy(di->udi_product, udev->product, sizeof(di->udi_product));
 	usb2_printBCD(di->udi_release, sizeof(di->udi_release),
 	    UGETW(udev->ddesc.bcdDevice));
 	di->udi_vendorNo = UGETW(udev->ddesc.idVendor);

Modified: head/sys/dev/usb/usb_hub.c
==============================================================================
--- head/sys/dev/usb/usb_hub.c	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_hub.c	Wed May 27 23:12:02 2009	(r192938)
@@ -1006,11 +1006,7 @@ uhub_child_pnpinfo_string(device_t paren
 		    UGETW(res.udev->ddesc.idProduct),
 		    res.udev->ddesc.bDeviceClass,
 		    res.udev->ddesc.bDeviceSubClass,
-#if USB_HAVE_STRINGS
 		    res.udev->serial,
-#else
-		    "",
-#endif
 		    iface->idesc->bInterfaceClass,
 		    iface->idesc->bInterfaceSubClass);
 	} else {

Modified: head/sys/dev/usb/usb_util.c
==============================================================================
--- head/sys/dev/usb/usb_util.c	Wed May 27 22:41:28 2009	(r192937)
+++ head/sys/dev/usb/usb_util.c	Wed May 27 23:12:02 2009	(r192938)
@@ -78,7 +78,6 @@ device_delete_all_children(device_t dev)
 void
 device_set_usb2_desc(device_t dev)
 {
-#if USB_HAVE_STRINGS
 	struct usb2_attach_arg *uaa;
 	struct usb2_device *udev;
 	struct usb2_interface *iface;
@@ -121,7 +120,6 @@ device_set_usb2_desc(device_t dev)
 	device_set_desc_copy(dev, temp_p);
 	device_printf(dev, "<%s> on %s\n", temp_p,
 	    device_get_nameunit(udev->bus->bdev));
-#endif
 }
 
 /*------------------------------------------------------------------------*
@@ -181,7 +179,6 @@ usb2_printBCD(char *p, uint16_t p_len, u
  * This function removes spaces at the beginning and the end of the string
  * pointed to by the "p" argument.
  *------------------------------------------------------------------------*/
-#if USB_HAVE_STRINGS
 void
 usb2_trim_spaces(char *p)
 {
@@ -198,7 +195,6 @@ usb2_trim_spaces(char *p)
 			e = p;
 	*e = 0;				/* kill trailing spaces */
 }
-#endif
 
 /*------------------------------------------------------------------------*
  *	usb2_make_str_desc - convert an ASCII string into a UNICODE string



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905272312.n4RNC2Nb015070>