On Mon, Jan 05, 2004 at 10:08:53PM +1030, Mark Smith wrote:
> Hi,
>
> I've been playing around with the new sysfs utilities, and
> noticed that, for the same USB device, the MaxPower value was
> different, when comparing the output of systool verses lsusb.
>
> It seems to be a kernel problem.
Yup, it's a bug. This patch fixes it.
thanks,
greg k-h
diff -Nru a/drivers/usb/core/driverfs.c b/drivers/usb/core/driverfs.c
--- a/drivers/usb/core/driverfs.c Mon Jan 5 14:04:26 2004
+++ b/drivers/usb/core/driverfs.c Mon Jan 5 14:04:26 2004
@@ -23,28 +23,29 @@
#include "usb.h"
/* Active configuration fields */
-#define usb_actconfig_show(field, format_string) \
-static ssize_t \
-show_##field (struct device *dev, char *buf) \
+#define usb_actconfig_show(field, multiplier, format_string) \
+static ssize_t show_##field (struct device *dev, char *buf) \
{ \
struct usb_device *udev; \
\
udev = to_usb_device (dev); \
- if (udev->actconfig) \
- return sprintf (buf, format_string, udev->actconfig->desc.field); \
- else return 0; \
+ if (udev->actconfig) \
+ return sprintf (buf, format_string, \
+ udev->actconfig->desc.field * multiplier); \
+ else \
+ return 0; \
} \
-#define usb_actconfig_attr(field, format_string) \
-usb_actconfig_show(field,format_string) \
+#define usb_actconfig_attr(field, multiplier, format_string) \
+usb_actconfig_show(field, multiplier, format_string) \
static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
-usb_actconfig_attr (bNumInterfaces, "%2d\n")
-usb_actconfig_attr (bmAttributes, "%2x\n")
-usb_actconfig_attr (bMaxPower, "%3dmA\n")
+usb_actconfig_attr (bNumInterfaces, 1, "%2d\n")
+usb_actconfig_attr (bmAttributes, 1, "%2x\n")
+usb_actconfig_attr (bMaxPower, 2, "%3dmA\n")
/* configuration value is always present, and r/w */
-usb_actconfig_show(bConfigurationValue,"%u\n");
+usb_actconfig_show(bConfigurationValue, 1, "%u\n");
static ssize_t
set_bConfigurationValue (struct device *dev, const char *buf, size_t count)
@@ -62,55 +63,25 @@
show_bConfigurationValue, set_bConfigurationValue);
/* String fields */
-static ssize_t show_product (struct device *dev, char *buf)
-{
- struct usb_device *udev;
- int len;
-
- udev = to_usb_device (dev);
-
- len = usb_string(udev, udev->descriptor.iProduct, buf, PAGE_SIZE);
- if (len < 0)
- return 0;
- buf[len] = '\n';
- buf[len+1] = 0;
- return len+1;
-}
-static DEVICE_ATTR(product,S_IRUGO,show_product,NULL);
-
-static ssize_t
-show_manufacturer (struct device *dev, char *buf)
-{
- struct usb_device *udev;
- int len;
-
- udev = to_usb_device (dev);
-
- len = usb_string(udev, udev->descriptor.iManufacturer, buf, PAGE_SIZE);
- if (len < 0)
- return 0;
- buf[len] = '\n';
- buf[len+1] = 0;
- return len+1;
-}
-static DEVICE_ATTR(manufacturer,S_IRUGO,show_manufacturer,NULL);
-
-static ssize_t
-show_serial (struct device *dev, char *buf)
-{
- struct usb_device *udev;
- int len;
-
- udev = to_usb_device (dev);
+#define usb_string_attr(name, field) \
+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); \
+ if (len < 0) \
+ return 0; \
+ buf[len] = '\n'; \
+ buf[len+1] = 0; \
+ return len+1; \
+} \
+static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
- len = usb_string(udev, udev->descriptor.iSerialNumber, buf, PAGE_SIZE);
- if (len < 0)
- return 0;
- buf[len] = '\n';
- buf[len+1] = 0;
- return len+1;
-}
-static DEVICE_ATTR(serial,S_IRUGO,show_serial,NULL);
+usb_string_attr(product, iProduct);
+usb_string_attr(manufacturer, iManufacturer);
+usb_string_attr(serial, iSerialNumber);
static ssize_t
show_speed (struct device *dev, char *buf)
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel