diff options
author | Oliver Neukum <oliver@neukum.org> | 2006-01-06 21:24:25 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-20 14:49:52 -0800 |
commit | 8781ba0aa9d9dd2870b75dba8d9a47e0f5a3f96a (patch) | |
tree | 164255fb2a2cf1bc87c3b214577bba401736da18 /drivers | |
parent | 60f780528f3ae603eb169a221628b93b6c6929f9 (diff) |
[PATCH] USB: optimise devio.c::usbdev_read
this is a small optimisation. It is ridiculous to do a kmalloc for
18 bytes. This puts it onto the stack.
Signed-off-by: Oliver Neukum <oliver@neukum.name>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/core/devio.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 2b68998fe4b..d01bd77e7b1 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -134,26 +134,21 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l } if (pos < sizeof(struct usb_device_descriptor)) { - struct usb_device_descriptor *desc = kmalloc(sizeof(*desc), GFP_KERNEL); - if (!desc) { - ret = -ENOMEM; - goto err; - } - memcpy(desc, &dev->descriptor, sizeof(dev->descriptor)); - le16_to_cpus(&desc->bcdUSB); - le16_to_cpus(&desc->idVendor); - le16_to_cpus(&desc->idProduct); - le16_to_cpus(&desc->bcdDevice); + struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */ + + memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor)); + le16_to_cpus(&temp_desc->bcdUSB); + le16_to_cpus(&temp_desc->idVendor); + le16_to_cpus(&temp_desc->idProduct); + le16_to_cpus(&temp_desc->bcdDevice); len = sizeof(struct usb_device_descriptor) - pos; if (len > nbytes) len = nbytes; - if (copy_to_user(buf, ((char *)desc) + pos, len)) { - kfree(desc); + if (copy_to_user(buf, ((char *)&temp_desc) + pos, len)) { ret = -EFAULT; goto err; } - kfree(desc); *ppos += len; buf += len; |