This should fix a lot of issues with broken devices that can't handle
retrieving strings
while they are doing something else (strings would be fetched from usbfs and
sysfs entries.)
Based on a patch that has been in the SuSE kernel tree for a long time from
Olaf Hering <[EMAIL PROTECTED]>
Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>
diff -Nru a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
--- a/drivers/usb/core/devices.c 2005-02-24 11:15:13 -08:00
+++ b/drivers/usb/core/devices.c 2005-02-24 11:15:13 -08:00
@@ -362,33 +362,21 @@
*/
static char *usb_dump_device_strings (char *start, char *end, struct
usb_device *dev)
{
- char *buf;
-
if (start > end)
return start;
- buf = kmalloc(128, GFP_KERNEL);
- if (!buf)
- return start;
- if (dev->descriptor.iManufacturer) {
- if (usb_string(dev, dev->descriptor.iManufacturer, buf, 128) >
0)
- start += sprintf(start, format_string_manufacturer,
buf);
- }
+ if (dev->manufacturer)
+ start += sprintf(start, format_string_manufacturer,
dev->manufacturer);
if (start > end)
goto out;
- if (dev->descriptor.iProduct) {
- if (usb_string(dev, dev->descriptor.iProduct, buf, 128) > 0)
- start += sprintf(start, format_string_product, buf);
- }
+ if (dev->product)
+ start += sprintf(start, format_string_product, dev->product);
if (start > end)
goto out;
#ifdef ALLOW_SERIAL_NUMBER
- if (dev->descriptor.iSerialNumber) {
- if (usb_string(dev, dev->descriptor.iSerialNumber, buf, 128) >
0)
- start += sprintf(start, format_string_serialnumber,
buf);
- }
+ if (dev->serial)
+ start += sprintf(start, format_string_serialnumber,
dev->serial);
#endif
out:
- kfree(buf);
return start;
}
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
--- a/drivers/usb/core/hub.c 2005-02-24 11:15:13 -08:00
+++ b/drivers/usb/core/hub.c 2005-02-24 11:15:13 -08:00
@@ -1102,23 +1102,31 @@
}
#ifdef DEBUG
-static void show_string(struct usb_device *udev, char *id, int index)
+static void show_string(struct usb_device *udev, char *id, char *string)
+{
+ if (!string)
+ return;
+ dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string);
+}
+
+#else
+static inline void show_string(struct usb_device *udev, char *id, int index)
+{}
+#endif
+
+static void get_string(struct usb_device *udev, char **string, int index)
{
char *buf;
if (!index)
return;
- if (!(buf = kmalloc(256, GFP_KERNEL)))
+ buf = kmalloc(256, GFP_KERNEL);
+ if (!buf)
return;
if (usb_string(udev, index, buf, 256) > 0)
- dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, buf);
- kfree(buf);
+ *string = buf;
}
-#else
-static inline void show_string(struct usb_device *udev, char *id, int index)
-{}
-#endif
#ifdef CONFIG_USB_OTG
#include "otg_whitelist.h"
@@ -1156,22 +1164,20 @@
goto fail;
}
+ /* read the standard strings and cache them if present */
+ get_string(udev, &udev->product, udev->descriptor.iProduct);
+ get_string(udev, &udev->manufacturer, udev->descriptor.iManufacturer);
+ get_string(udev, &udev->serial, udev->descriptor.iSerialNumber);
+
/* Tell the world! */
dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, "
"SerialNumber=%d\n",
udev->descriptor.iManufacturer,
udev->descriptor.iProduct,
udev->descriptor.iSerialNumber);
-
- if (udev->descriptor.iProduct)
- show_string(udev, "Product",
- udev->descriptor.iProduct);
- if (udev->descriptor.iManufacturer)
- show_string(udev, "Manufacturer",
- udev->descriptor.iManufacturer);
- if (udev->descriptor.iSerialNumber)
- show_string(udev, "SerialNumber",
- udev->descriptor.iSerialNumber);
+ show_string(udev, "Product", udev->product);
+ show_string(udev, "Manufacturer", udev->manufacturer);
+ show_string(udev, "SerialNumber", udev->serial);
#ifdef CONFIG_USB_OTG
/*
diff -Nru a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
--- a/drivers/usb/core/sysfs.c 2005-02-24 11:15:13 -08:00
+++ b/drivers/usb/core/sysfs.c 2005-02-24 11:15:13 -08:00
@@ -89,14 +89,14 @@
show_bConfigurationValue, set_bConfigurationValue);
/* String fields */
-#define usb_string_attr(name, field) \
+#define usb_string_attr(name) \
static ssize_t show_##name(struct device *dev, char *buf) \
{ \
struct usb_device *udev; \
int len; \
\
udev = to_usb_device (dev); \
- len = usb_string(udev, udev->descriptor.field, buf, PAGE_SIZE); \
+ len = snprintf(buf, 256, "%s", udev->name); \
if (len < 0) \
return 0; \
buf[len] = '\n'; \
@@ -105,9 +105,9 @@
} \
static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
-usb_string_attr(product, iProduct);
-usb_string_attr(manufacturer, iManufacturer);
-usb_string_attr(serial, iSerialNumber);
+usb_string_attr(product);
+usb_string_attr(manufacturer);
+usb_string_attr(serial);
static ssize_t
show_speed (struct device *dev, char *buf)
@@ -230,11 +230,11 @@
sysfs_create_group(&dev->kobj, &dev_attr_grp);
- if (udev->descriptor.iManufacturer)
+ if (udev->manufacturer)
device_create_file (dev, &dev_attr_manufacturer);
- if (udev->descriptor.iProduct)
+ if (udev->product)
device_create_file (dev, &dev_attr_product);
- if (udev->descriptor.iSerialNumber)
+ if (udev->serial)
device_create_file (dev, &dev_attr_serial);
device_create_file (dev, &dev_attr_configuration);
}
diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c 2005-02-24 11:15:13 -08:00
+++ b/drivers/usb/core/usb.c 2005-02-24 11:15:13 -08:00
@@ -647,7 +647,10 @@
usb_destroy_configuration(udev);
usb_bus_put(udev->bus);
- kfree (udev);
+ kfree(udev->product);
+ kfree(udev->manufacturer);
+ kfree(udev->serial);
+ kfree(udev);
}
/**
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h 2005-02-24 11:15:13 -08:00
+++ b/include/linux/usb.h 2005-02-24 11:15:13 -08:00
@@ -342,6 +342,9 @@
int have_langid; /* whether string_langid is valid yet */
int string_langid; /* language ID for strings */
+ char *product;
+ char *manufacturer;
+ char *serial; /* static strings from the device */
struct list_head filelist;
struct dentry *usbfs_dentry; /* usbfs dentry entry for the device */
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel