This version doesn't oops and is perspicuous.
I haved tested it in the "both strings" case (which made the old code
oops) and in the "no strings" case.
-ch
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--- linux-2.5.26-rmk1/drivers/usb/core/usb.c Tue Jul 16 16:49:34 2002
+++ linux-2.5.26-rmk1-ch1/drivers/usb/core/usb.c Mon Jul 22 01:50:08 2002
@@ -1221,56 +1221,59 @@ int usb_set_address(struct usb_device *d
*/
static void set_device_description (struct usb_device *dev)
{
- char *buf, *here, *end;
- int mfgr = dev->descriptor.iManufacturer;
- int prod = dev->descriptor.iProduct;
+ void *buf;
+ int iMfgr = dev->descriptor.iManufacturer;
+ int iProd = dev->descriptor.iProduct;
+ int idVendor = dev->descriptor.idVendor;
+ int idProduct = dev->descriptor.idProduct;
+ char *sMfgr, *sProd;
- /* 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;
+ idVendor, idProduct);
- 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;
+
+ sProd = (char *) buf;
+ sMfgr = (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 (iProd && usb_string (dev, iProd, sProd, 256) > 0) {
#ifdef DEBUG
- printk (KERN_INFO "Product: %s\n", buf);
+ printk (KERN_INFO "Product: %s\n", sProd);
#endif
} else {
- buf [0] = 0;
- prod = -1;
+ sProd = 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 (iMfgr && usb_string (dev, iMfgr, sMfgr, 256) > 0) {
#ifdef DEBUG
- printk (KERN_INFO "Manufacturer: %s\n", buf);
+ printk (KERN_INFO "Manufacturer: %s\n", sMfgr);
#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 */
+ sMfgr = 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 (sProd && sMfgr) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "%s (%s)", sProd, sMfgr);
+ } else if (sProd) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "%s (USB device %04x:%04x)",
+ sProd, idVendor, idProduct);
+ } else if (sMfgr) {
+ snprintf(dev->dev.name, sizeof dev->dev.name,
+ "USB device %04x:%04x (%s)",
+ idVendor, idProduct, sMfgr);
}
+
kfree(buf);
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel