Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 61932
b: refs/heads/master
c: 69d42a7
h: refs/heads/master
v: v3
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed Jul 20, 2007
1 parent c02b474 commit 8e1b45e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1b4cd43bd3f9aa7a794e29b80b0d984a8e144df4
refs/heads/master: 69d42a78f935d19384d1f6e4f94b65bb162b36df
53 changes: 53 additions & 0 deletions trunk/drivers/usb/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,54 @@ static struct attribute_group dev_attr_grp = {
.attrs = dev_attrs,
};

/* Binary descriptors */

static ssize_t
read_descriptors(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct usb_device *udev = to_usb_device(
container_of(kobj, struct device, kobj));
size_t nleft = count;
size_t srclen, n;

usb_lock_device(udev);

/* The binary attribute begins with the device descriptor */
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) {
int cfgno = udev->actconfig - udev->config;

srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength);
if (off < srclen) {
n = min_t(size_t, nleft, srclen - off);
memcpy(buf, off + udev->rawdescriptors[cfgno], n);
nleft -= n;
}
}
usb_unlock_device(udev);
return count - nleft;
}

static struct bin_attribute dev_bin_attr_descriptors = {
.attr = {.name = "descriptors", .mode = 0444},
.read = read_descriptors,
.size = 18 + 65535, /* dev descr + max-size raw descriptor */
};

int usb_create_sysfs_dev_files(struct usb_device *udev)
{
struct device *dev = &udev->dev;
Expand All @@ -450,6 +498,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev)
if (retval)
return retval;

retval = device_create_bin_file(dev, &dev_bin_attr_descriptors);
if (retval)
goto error;

retval = add_persist_attributes(dev);
if (retval)
goto error;
Expand Down Expand Up @@ -492,6 +544,7 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
device_remove_file(dev, &dev_attr_serial);
remove_power_attributes(dev);
remove_persist_attributes(dev);
device_remove_bin_file(dev, &dev_bin_attr_descriptors);
sysfs_remove_group(&dev->kobj, &dev_attr_grp);
}

Expand Down

0 comments on commit 8e1b45e

Please sign in to comment.