aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/devio.c
diff options
context:
space:
mode:
authorOliver Neukum <oliver@neukum.org>2006-01-06 15:24:25 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 17:49:52 -0500
commit8781ba0aa9d9dd2870b75dba8d9a47e0f5a3f96a (patch)
tree164255fb2a2cf1bc87c3b214577bba401736da18 /drivers/usb/core/devio.c
parent60f780528f3ae603eb169a221628b93b6c6929f9 (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/usb/core/devio.c')
-rw-r--r--drivers/usb/core/devio.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 2b68998fe4b3..d01bd77e7b14 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
134 } 134 }
135 135
136 if (pos < sizeof(struct usb_device_descriptor)) { 136 if (pos < sizeof(struct usb_device_descriptor)) {
137 struct usb_device_descriptor *desc = kmalloc(sizeof(*desc), GFP_KERNEL); 137 struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */
138 if (!desc) { 138
139 ret = -ENOMEM; 139 memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor));
140 goto err; 140 le16_to_cpus(&temp_desc->bcdUSB);
141 } 141 le16_to_cpus(&temp_desc->idVendor);
142 memcpy(desc, &dev->descriptor, sizeof(dev->descriptor)); 142 le16_to_cpus(&temp_desc->idProduct);
143 le16_to_cpus(&desc->bcdUSB); 143 le16_to_cpus(&temp_desc->bcdDevice);
144 le16_to_cpus(&desc->idVendor);
145 le16_to_cpus(&desc->idProduct);
146 le16_to_cpus(&desc->bcdDevice);
147 144
148 len = sizeof(struct usb_device_descriptor) - pos; 145 len = sizeof(struct usb_device_descriptor) - pos;
149 if (len > nbytes) 146 if (len > nbytes)
150 len = nbytes; 147 len = nbytes;
151 if (copy_to_user(buf, ((char *)desc) + pos, len)) { 148 if (copy_to_user(buf, ((char *)&temp_desc) + pos, len)) {
152 kfree(desc);
153 ret = -EFAULT; 149 ret = -EFAULT;
154 goto err; 150 goto err;
155 } 151 }
156 kfree(desc);
157 152
158 *ppos += len; 153 *ppos += len;
159 buf += len; 154 buf += len;