[PATCH] USB: use stack allocation for struct usb_ctrlrequest

Wu Fengguang
2008-12-10T07:33:19Z

sizeof(struct usb_ctrlrequest) = 8, which is as small as the *dt pointer
in a 64bit system.

Cc: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
drivers/usb/core/message.c | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)

--- linux-2.6.orig/drivers/usb/core/message.c
+++ linux-2.6/drivers/usb/core/message.c
@@ -130,26 +130,15 @@ int usb_control_msg(struct usb_device *d
__u8 requesttype, __u16 value, __u16 index, void *data,
__u16 size, int timeout)
{
- struct usb_ctrlrequest *dr;
- int ret;
-
- dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
- if (!dr)
- return -ENOMEM;
-
- dr->bRequestType = requesttype;
- dr->bRequest = request;
- dr->wValue = cpu_to_le16p(&value);
- dr->wIndex = cpu_to_le16p(&index);
- dr->wLength = cpu_to_le16p(&size);
+ struct usb_ctrlrequest dr = {
+ .bRequestType = requesttype,
+ .bRequest = request,
+ .wValue = cpu_to_le16p(&value),
+ .wIndex = cpu_to_le16p(&index),
+ .wLength = cpu_to_le16p(&size),
+ };

- /* dbg("usb_control_msg"); */
-
- ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
-
- kfree(dr);
-
- return ret;
+ return usb_internal_control_msg(dev, pipe, &dr, data, size, timeout);
}
EXPORT_SYMBOL_GPL(usb_control_msg);