summaryrefslogtreecommitdiff
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorChristopher Hoover <ch@hpl.hp.com>2002-07-22 02:09:07 -0700
committerGreg Kroah-Hartman <greg@kroah.com>2002-07-22 02:09:07 -0700
commit271ae4b3fd07f1ab69ad4ebc7494f3c8b34026d7 (patch)
tree4a10b226e1798d5e5de9af236bbecfe4ece1dfc4 /drivers/usb/core
parenteabb444f5df667939be7be503479768cf97c48a8 (diff)
[PATCH] set_device_description oops fixage mk2
Unlike previous version, this one doesn't oops and is perspicuous. Please apply.
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/usb.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index ed2e03089e57..89431d2a1d7c 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1288,56 +1288,59 @@ int usb_set_address(struct usb_device *dev)
*/
static void set_device_description (struct usb_device *dev)
{
- char *buf, *here, *end;
+ void *buf;
int mfgr = dev->descriptor.iManufacturer;
int prod = dev->descriptor.iProduct;
+ int vendor_id = dev->descriptor.idVendor;
+ int product_id = dev->descriptor.idProduct;
+ char *mfgr_str, *prod_str;
- /* set default; keep it if there are no strings */
+ /* set default; keep it if there are no strings, or kmalloc fails */
sprintf (dev->dev.name, "USB device %04x:%04x",
- dev->descriptor.idVendor,
- dev->descriptor.idProduct);
- if (!mfgr && !prod)
- return;
+ vendor_id, product_id);
- if (!(buf = kmalloc(256, GFP_KERNEL)))
+ if (!(buf = kmalloc(256 * 2, GFP_KERNEL)))
return;
- here = dev->dev.name;
- end = here + sizeof dev->dev.name - 2;
- *end = 0;
+
+ prod_str = (char *) buf;
+ mfgr_str = (char *) buf + 256;
- /* much like pci ... describe as either:
- * - both strings: 'product descr (vendor descr)'
- * - product only: 'product descr (USB device vvvv:pppp)'
- * - vendor only: 'USB device vvvv:pppp (vendor descr)'
- * - neither string: 'USB device vvvv:pppp'
- */
- if (prod && usb_string (dev, prod, buf, 256) > 0) {
- strncpy (here, buf, end - here);
+ if (prod && usb_string (dev, prod, prod_str, 256) > 0) {
#ifdef DEBUG
- printk (KERN_INFO "Product: %s\n", buf);
+ printk (KERN_INFO "Product: %s\n", prod_str);
#endif
} else {
- buf [0] = 0;
- prod = -1;
+ prod_str = 0;
}
- here = strchr (here, 0);
- if (mfgr && usb_string (dev, mfgr, buf, 256) > 0) {
- *here++ = ' ';
- *here++ = '(';
- strncpy (here, buf, end - here - 1);
- here = strchr (here, 0);
- *here++ = ')';
+
+ if (mfgr && usb_string (dev, mfgr, mfgr_str, 256) > 0) {
#ifdef DEBUG
- printk (KERN_INFO "Manufacturer: %s\n", buf);
+ printk (KERN_INFO "Manufacturer: %s\n", mfgr_str);
#endif
} else {
- if (prod != -1)
- snprintf (here, end - here - 1,
- " (USB device %04x:%04x)",
- dev->descriptor.idVendor,
- dev->descriptor.idProduct);
- /* both strings unavailable, keep the default */
+ mfgr_str = 0;
}
+
+ /* much like pci ... describe as either:
+ * - both strings: 'product descr (vendor descr)'
+ * - product only: 'product descr (USB device vvvv:pppp)'
+ * - vendor only: 'USB device vvvv:pppp (vendor descr)'
+ * - neither string: 'USB device vvvv:pppp'
+ */
+
+ if (prod_str && mfgr_str) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "%s (%s)", prod_str, mfgr_str);
+ } else if (prod_str) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "%s (USB device %04x:%04x)",
+ prod_str, vendor_id, product_id);
+ } else if (mfgr_str) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "USB device %04x:%04x (%s)",
+ vendor_id, product_id, mfgr_str);
+ }
+
kfree(buf);
}