Commit 217a9081 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: add all configs to the "descriptors" attribute

This patch (as1094) changes the output of the "descriptors" binary
attribute.  Now it will contain the device descriptor followed by all
the configuration descriptors, not just the descriptor for the current
config.

Userspace libraries want to have access to the kernel's cached
descriptor information, so they can learn about device characteristics
without having to wake up suspended devices.  So far the only user of
this attribute is the new libusb-1.0 library; thus changing its
contents shouldn't cause any problems.

This should be considered for 2.6.26, if for no other reason than to
minimize the range of releases in which the attribute contains only the
current config descriptor.

Also, it doesn't hurt that the patch removes the device locking --
which was formerly needed in order to know for certain which config was
indeed current.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e16362a0
...@@ -588,35 +588,33 @@ read_descriptors(struct kobject *kobj, struct bin_attribute *attr, ...@@ -588,35 +588,33 @@ read_descriptors(struct kobject *kobj, struct bin_attribute *attr,
container_of(kobj, struct device, kobj)); container_of(kobj, struct device, kobj));
size_t nleft = count; size_t nleft = count;
size_t srclen, n; size_t srclen, n;
int cfgno;
void *src;
usb_lock_device(udev); /* The binary attribute begins with the device descriptor.
* Following that are the raw descriptor entries for all the
/* The binary attribute begins with the device descriptor */ * configurations (config plus subsidiary descriptors).
srclen = sizeof(struct usb_device_descriptor);
if (off < srclen) {
n = min_t(size_t, nleft, srclen - off);
memcpy(buf, off + (char *) &udev->descriptor, n);
nleft -= n;
buf += n;
off = 0;
} else {
off -= srclen;
}
/* Then follows the raw descriptor entry for the current
* configuration (config plus subsidiary descriptors).
*/ */
if (udev->actconfig) { for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
int cfgno = udev->actconfig - udev->config; nleft > 0; ++cfgno) {
if (cfgno < 0) {
srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength); src = &udev->descriptor;
srclen = sizeof(struct usb_device_descriptor);
} else {
src = udev->rawdescriptors[cfgno];
srclen = __le16_to_cpu(udev->config[cfgno].desc.
wTotalLength);
}
if (off < srclen) { if (off < srclen) {
n = min_t(size_t, nleft, srclen - off); n = min(nleft, srclen - (size_t) off);
memcpy(buf, off + udev->rawdescriptors[cfgno], n); memcpy(buf, src + off, n);
nleft -= n; nleft -= n;
buf += n;
off = 0;
} else {
off -= srclen;
} }
} }
usb_unlock_device(udev);
return count - nleft; return count - nleft;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment