From: Wu Fengguang <fengguang.wu@intel.com>
To: Laurent Pinchart <laurent.pinchart@skynet.be>
Cc: LKML <linux-kernel@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@suse.de>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] USB: use stack allocation for struct usb_ctrlrequest
Date: Wed, 10 Dec 2008 20:43:11 +0800 [thread overview]
Message-ID: <20081210124308.GB6772@localhost> (raw)
In-Reply-To: <200812101040.09886.laurent.pinchart@skynet.be>
Hi Laurent,
On Wed, Dec 10, 2008 at 11:40:09AM +0200, Laurent Pinchart wrote:
> Hi Wu,
>
> On Wednesday 10 December 2008, Wu Fengguang wrote:
> > sizeof(struct usb_ctrlrequest) = 8, which is as small as the *dt pointer
> > in a 64bit system.
>
> The usb_ctrlrequest pointer is passed down to the hardware and must point to
> DMA-able memory. For this reason you can't use the stack and must kmalloc()
> the structure.
Ah thanks for the background. Does GFP_NOIO guarantee that?
e.g. what if the memory is allocated from ZONE_HIGHMEM?
Thanks,
Fengguang
>
> > 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);
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2008-12-10 13:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-10 7:32 [PATCH] USB: use stack allocation for struct usb_ctrlrequest Wu Fengguang
2008-12-10 9:40 ` Laurent Pinchart
2008-12-10 12:43 ` Wu Fengguang [this message]
2008-12-10 14:07 ` Gilad Ben-Yossef
2008-12-10 14:23 ` Wu Fengguang
2008-12-10 14:31 ` Gilad Ben-Yossef
2008-12-11 0:01 ` Pete Zaitcev
2008-12-11 0:57 ` Robert Hancock
2008-12-11 0:59 ` Robert Hancock
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=20081210124308.GB6772@localhost \
--to=fengguang.wu@intel.com \
--cc=gregkh@suse.de \
--cc=laurent.pinchart@skynet.be \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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