On Thu, Feb 24, 2005 at 09:04:51PM +0100, Olaf Hering wrote:
>  On Thu, Feb 24, Greg KH wrote:
> 
> > On Thu, Feb 24, 2005 at 08:53:57PM +0100, Olaf Hering wrote:
> > >  On Thu, Feb 24, Greg KH wrote:
> > > 
> > > > I've changed my mind.
> > > 
> > > Thanks Greg. Did you catch all usb_string() users for sysfs attributes?
> > 
> > I sure hope I did, if not, please let me know.
> 
> two more users:
> usb_intf_str (interface, iInterface);
> usb_actconfig_str (configuration, iConfiguration);

And here's the patch to fix up the iConfiguration string.

I'll go touch up the remaining drivers, but I think we've covered all
the sysfs entries now.

thanks,

greg k-h

-----

USB: cache the iConfiguration string, if present.

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

diff -Nru a/drivers/usb/core/config.c b/drivers/usb/core/config.c
--- a/drivers/usb/core/config.c 2005-02-24 15:07:55 -08:00
+++ b/drivers/usb/core/config.c 2005-02-24 15:07:55 -08:00
@@ -420,6 +420,9 @@
        for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
                struct usb_host_config *cf = &dev->config[c];
 
+               if (cf->string)
+                       kfree(cf->string);
+
                for (i = 0; i < cf->desc.bNumInterfaces; i++) {
                        if (cf->intf_cache[i])
                                kref_put(&cf->intf_cache[i]->ref, 
diff -Nru a/drivers/usb/core/message.c b/drivers/usb/core/message.c
--- a/drivers/usb/core/message.c        2005-02-24 15:07:55 -08:00
+++ b/drivers/usb/core/message.c        2005-02-24 15:07:55 -08:00
@@ -1413,6 +1413,13 @@
                }
                kfree(new_interfaces);
 
+               if ((cp->desc.iConfiguration) &&
+                   (cp->string == NULL)) {
+                       cp->string = kmalloc(256, GFP_KERNEL);
+                       if (cp->string)
+                               usb_string(dev, cp->desc.iConfiguration, 
cp->string, 256);
+               }
+
                /* Now that all the interfaces are set up, register them
                 * to trigger binding of drivers to interfaces.  probe()
                 * routines may install different altsettings and may
diff -Nru a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
--- a/drivers/usb/core/sysfs.c  2005-02-24 15:07:55 -08:00
+++ b/drivers/usb/core/sysfs.c  2005-02-24 15:07:55 -08:00
@@ -46,27 +46,24 @@
 usb_actconfig_attr (bmAttributes, 1, "%2x\n")
 usb_actconfig_attr (bMaxPower, 2, "%3dmA\n")
 
-#define usb_actconfig_str(name, field)                                 \
-static ssize_t  show_##name(struct device *dev, char *buf)             \
-{                                                                      \
-       struct usb_device *udev;                                        \
-       struct usb_host_config *actconfig;                              \
-       int len;                                                        \
-                                                                       \
-       udev = to_usb_device (dev);                                     \
-       actconfig = udev->actconfig;                                    \
-       if (!actconfig)                                                 \
-               return 0;                                               \
-       len = usb_string(udev, actconfig->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);
+static ssize_t show_configuration_string(struct device *dev, char *buf)
+{
+       struct usb_device *udev;
+       struct usb_host_config *actconfig;
+       int len;
 
-usb_actconfig_str (configuration, iConfiguration)
+       udev = to_usb_device (dev);
+       actconfig = udev->actconfig;
+       if ((!actconfig) || (!actconfig->string))
+               return 0;
+       len = sprintf(buf, actconfig->string, PAGE_SIZE);
+       if (len < 0)
+               return 0;
+       buf[len] = '\n';
+       buf[len+1] = 0;
+       return len+1;
+}
+static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
 
 /* configuration value is always present, and r/w */
 usb_actconfig_show(bConfigurationValue, 1, "%u\n");
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h       2005-02-24 15:07:55 -08:00
+++ b/include/linux/usb.h       2005-02-24 15:07:55 -08:00
@@ -190,6 +190,8 @@
 /**
  * struct usb_host_config - representation of a device's configuration
  * @desc: the device's configuration descriptor.
+ * @string: pointer to the cached version of the iConfiguration string, if
+ *     present for this configuration.
  * @interface: array of pointers to usb_interface structures, one for each
  *     interface in the configuration.  The number of interfaces is stored
  *     in desc.bNumInterfaces.  These pointers are valid only while the
@@ -226,6 +228,7 @@
 struct usb_host_config {
        struct usb_config_descriptor    desc;
 
+       char *string;
        /* the interfaces associated with this configuration,
         * stored in no particular order */
        struct usb_interface *interface[USB_MAXINTERFACES];


-------------------------------------------------------
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

Reply via email to