ChangeSet 1.2020.1.141, 2005/03/08 00:54:56-08:00, [EMAIL PROTECTED]

[PATCH] USB: make iInterface string cached

Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>


 drivers/usb/core/message.c |    9 +++++++++
 drivers/usb/core/sysfs.c   |   39 ++++++++++++++++++---------------------
 include/linux/usb.h        |    1 +
 3 files changed, 28 insertions(+), 21 deletions(-)


diff -Nru a/drivers/usb/core/message.c b/drivers/usb/core/message.c
--- a/drivers/usb/core/message.c        2005-03-08 16:40:48 -08:00
+++ b/drivers/usb/core/message.c        2005-03-08 16:40:48 -08:00
@@ -988,6 +988,8 @@
                        dev_dbg (&dev->dev, "unregistering interface %s\n",
                                interface->dev.bus_id);
                        usb_remove_sysfs_intf_files(interface);
+                       kfree(interface->cur_altsetting->string);
+                       interface->cur_altsetting->string = NULL;
                        device_del (&interface->dev);
                }
 
@@ -1433,6 +1435,13 @@
                                        intf->dev.bus_id,
                                        ret);
                                continue;
+                       }
+                       if ((intf->cur_altsetting->desc.iInterface) &&
+                           (intf->cur_altsetting->string == NULL)) {
+                               intf->cur_altsetting->string = kmalloc(256, 
GFP_KERNEL);
+                               if (intf->cur_altsetting->string)
+                                       usb_string(dev, 
intf->cur_altsetting->desc.iInterface,
+                                                  
intf->cur_altsetting->string, 256);
                        }
                        usb_create_sysfs_intf_files (intf);
                }
diff -Nru a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
--- a/drivers/usb/core/sysfs.c  2005-03-08 16:40:48 -08:00
+++ b/drivers/usb/core/sysfs.c  2005-03-08 16:40:48 -08:00
@@ -272,25 +272,22 @@
 usb_intf_attr (bInterfaceSubClass, "%02x\n")
 usb_intf_attr (bInterfaceProtocol, "%02x\n")
 
-#define usb_intf_str(name, field)                                      \
-static ssize_t  show_##name(struct device *dev, char *buf)             \
-{                                                                      \
-       struct usb_interface *intf;                                     \
-       struct usb_device *udev;                                        \
-       int len;                                                        \
-                                                                       \
-       intf = to_usb_interface (dev);                                  \
-       udev = interface_to_usbdev (intf);                              \
-       len = usb_string(udev, intf->cur_altsetting->desc.field, buf, 
PAGE_SIZE);\
-       if (len < 0)                                                    \
-               return 0;                                               \
-       buf[len] = '\n';                                                \
-       buf[len+1] = 0;                                                 \
-       return len+1;                                                   \
-}                                                                      \
-static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
-
-usb_intf_str (interface, iInterface);
+static ssize_t show_interface_string(struct device *dev, char *buf)
+{
+       struct usb_interface *intf;
+       struct usb_device *udev;
+       int len;
+
+       intf = to_usb_interface (dev);
+       udev = interface_to_usbdev (intf);
+       len = snprintf(buf, 256, "%s", intf->cur_altsetting->string);
+       if (len < 0)
+               return 0;
+       buf[len] = '\n';
+       buf[len+1] = 0;
+       return len+1;
+}
+static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
 
 static struct attribute *intf_attrs[] = {
        &dev_attr_bInterfaceNumber.attr,
@@ -309,7 +306,7 @@
 {
        sysfs_create_group(&intf->dev.kobj, &intf_attr_grp);
 
-       if (intf->cur_altsetting->desc.iInterface)
+       if (intf->cur_altsetting->string)
                device_create_file(&intf->dev, &dev_attr_interface);
                
 }
@@ -318,7 +315,7 @@
 {
        sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp);
 
-       if (intf->cur_altsetting->desc.iInterface)
+       if (intf->cur_altsetting->string)
                device_remove_file(&intf->dev, &dev_attr_interface);
 
 }
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h       2005-03-08 16:40:48 -08:00
+++ b/include/linux/usb.h       2005-03-08 16:40:48 -08:00
@@ -70,6 +70,7 @@
         */
        struct usb_host_endpoint *endpoint;
 
+       char *string;           /* iInterface string, if present */
        unsigned char *extra;   /* Extra descriptors */
        int extralen;
 };



-------------------------------------------------------
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_ide95&alloc_id396&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to