[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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
60f780528f
commit
8781ba0aa9
@@ -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)) {
|
if (pos < sizeof(struct usb_device_descriptor)) {
|
||||||
struct usb_device_descriptor *desc = kmalloc(sizeof(*desc), GFP_KERNEL);
|
struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */
|
||||||
if (!desc) {
|
|
||||||
ret = -ENOMEM;
|
memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor));
|
||||||
goto err;
|
le16_to_cpus(&temp_desc->bcdUSB);
|
||||||
}
|
le16_to_cpus(&temp_desc->idVendor);
|
||||||
memcpy(desc, &dev->descriptor, sizeof(dev->descriptor));
|
le16_to_cpus(&temp_desc->idProduct);
|
||||||
le16_to_cpus(&desc->bcdUSB);
|
le16_to_cpus(&temp_desc->bcdDevice);
|
||||||
le16_to_cpus(&desc->idVendor);
|
|
||||||
le16_to_cpus(&desc->idProduct);
|
|
||||||
le16_to_cpus(&desc->bcdDevice);
|
|
||||||
|
|
||||||
len = sizeof(struct usb_device_descriptor) - pos;
|
len = sizeof(struct usb_device_descriptor) - pos;
|
||||||
if (len > nbytes)
|
if (len > nbytes)
|
||||||
len = nbytes;
|
len = nbytes;
|
||||||
if (copy_to_user(buf, ((char *)desc) + pos, len)) {
|
if (copy_to_user(buf, ((char *)&temp_desc) + pos, len)) {
|
||||||
kfree(desc);
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
kfree(desc);
|
|
||||||
|
|
||||||
*ppos += len;
|
*ppos += len;
|
||||||
buf += len;
|
buf += len;
|
||||||
|
Reference in New Issue
Block a user