From: Masatake YAMATO <jet@gyve.org>
To: linux-usb-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Avoid to use kmalloc in usb/core/message.c
Date: Tue, 05 Jul 2005 19:12:21 +0900 (JST) [thread overview]
Message-ID: <20050705.191221.92572119.jet@gyve.org> (raw)
In some functions in drivers/usb/core/message.c kmalloc is used to
allocate fix size of memory chunks; and the chunks is freed at the end
of each functions. The sizes are not so large: 8(struct
usb_ctrlrequest), 18(struct usb_device_descriptor), and 2(u16) bytes.
I wonder why the invocations of kmalloc are needed in these functions.
Following patch is for avoiding invocations of kmalloc. Instead stacks
are used.
The patch is generated by co-diff against
rsync://kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Signed-off-by: Masatake YAMATO <jet@gyve.org>
Index: drivers/usb/core/message.c
===================================================================
--- 6f51e67e4a433ee0ff866a6ac18a4bce798fe0c7/drivers/usb/core/message.c (mode:100644)
+++ uncommitted/drivers/usb/core/message.c (mode:100644)
@@ -142,11 +142,9 @@
int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype,
__u16 value, __u16 index, void *data, __u16 size, int timeout)
{
- struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
+ struct usb_ctrlrequest dr_rec;
+ struct usb_ctrlrequest *dr = &dr_rec;
int ret;
-
- if (!dr)
- return -ENOMEM;
dr->bRequestType= requesttype;
dr->bRequest = request;
@@ -158,7 +156,6 @@
ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
- kfree(dr);
return ret;
}
@@ -794,19 +791,17 @@
*/
int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
{
+ struct usb_device_descriptor desc_rec;
struct usb_device_descriptor *desc;
int ret;
if (size > sizeof(*desc))
return -EINVAL;
- desc = kmalloc(sizeof(*desc), GFP_NOIO);
- if (!desc)
- return -ENOMEM;
+ desc = &desc_rec;
ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);
if (ret >= 0)
memcpy(&dev->descriptor, desc, size);
- kfree(desc);
return ret;
}
@@ -835,17 +830,13 @@
int usb_get_status(struct usb_device *dev, int type, int target, void *data)
{
int ret;
- u16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
-
- if (!status)
- return -ENOMEM;
+ u16 status;
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
- USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status,
- sizeof(*status), USB_CTRL_GET_TIMEOUT);
+ USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, &status,
+ sizeof(status), USB_CTRL_GET_TIMEOUT);
- *(u16 *)data = *status;
- kfree(status);
+ *(u16 *)data = status;
return ret;
}
next reply other threads:[~2005-07-05 10:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-05 10:12 Masatake YAMATO [this message]
2005-07-05 10:36 ` Duncan Sands
2005-07-05 11:22 ` Arjan van de Ven
2005-07-05 13:00 ` Duncan Sands
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050705.191221.92572119.jet@gyve.org \
--to=jet@gyve.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®