From: Greg KH <gregkh@linuxfoundation.org>
To: walter harms <wharms@bfs.de>
Cc: Kumar Amit Mehta <gmate.amit@gmail.com>,
devel@driverdev.osuosl.org, fmhess@users.sourceforge.net,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
abbotti@mev.co.uk
Subject: Re: [PATCH 2/2] staging: comedi: drivers: usbduxfast.c: fix for DMA buffers on stack
Date: Fri, 22 Feb 2013 11:06:44 -0800 [thread overview]
Message-ID: <20130222190644.GA16011@kroah.com> (raw)
In-Reply-To: <5127BFDB.4010608@bfs.de>
On Fri, Feb 22, 2013 at 07:58:35PM +0100, walter harms wrote:
>
>
> Am 22.02.2013 19:07, schrieb Kumar Amit Mehta:
> > fix for instances of DMA buffer on stack(being passed to usb_control_msg) for
> > the USB-DUXfast Board driver.
> >
> > Signed-off-by: Kumar Amit Mehta <gmate.amit@gmail.com>
> > ---
> > drivers/staging/comedi/drivers/usbduxfast.c | 30 ++++++++++++++++-----------
> > 1 file changed, 18 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
> > index 4bf5dd0..1ba0e3d 100644
> > --- a/drivers/staging/comedi/drivers/usbduxfast.c
> > +++ b/drivers/staging/comedi/drivers/usbduxfast.c
> > @@ -436,10 +436,14 @@ static void usbduxfastsub_ai_Irq(struct urb *urb)
> > static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
> > {
> > int ret;
> > - unsigned char local_transfer_buffer[16];
> > + unsigned char *local_transfer_buffer;
> > +
> > + local_transfer_buffer = kmalloc(1, GFP_KERNEL);
> > + if (!local_transfer_buffer)
> > + return -ENOMEM;
> >
> > /* 7f92 to zero */
> > - local_transfer_buffer[0] = 0;
> > + *local_transfer_buffer = 0;
> > /* bRequest, "Firmware" */
> > ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
> > USBDUXFASTSUB_FIRMWARE,
> > @@ -450,22 +454,25 @@ static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
> > local_transfer_buffer,
> > 1, /* Length */
> > EZTIMEOUT); /* Timeout */
> > - if (ret < 0) {
> > + if (ret < 0)
> > dev_err(&udfs->interface->dev,
> > "control msg failed (start)\n");
> > - return ret;
> > - }
> >
> > - return 0;
> > + kfree(local_transfer_buffer);
> > + return ret;
> > }
> >
> > static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
> > {
> > int ret;
> > - unsigned char local_transfer_buffer[16];
> > + unsigned char *local_transfer_buffer;
> > +
> > + local_transfer_buffer = kmalloc(1, GFP_KERNEL);
> > + if (!local_transfer_buffer)
> > + return -ENOMEM;
> >
> > /* 7f92 to one */
> > - local_transfer_buffer[0] = 1;
> > + *local_transfer_buffer = 1;
> > /* bRequest, "Firmware" */
> > ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
> > USBDUXFASTSUB_FIRMWARE,
> > @@ -474,13 +481,12 @@ static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
> > 0x0000, /* Index */
> > local_transfer_buffer, 1, /* Length */
> > EZTIMEOUT); /* Timeout */
> > - if (ret < 0) {
> > + if (ret < 0)
> > dev_err(&udfs->interface->dev,
> > "control msg failed (stop)\n");
> > - return ret;
> > - }
> >
> > - return 0;
> > + kfree(local_transfer_buffer);
> > + return ret;
> > }
> >
> > static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs,
>
> mmh, it seems a bit overheat to alloc 1 byte.
> Could one of the driver maintainers please comment
> is that realy need ?
Yes it is needed.
> or is it possible to pass one byte
> in a register ? (aka char/int) without allocating ?
Nope, the USB host controllers must be able to DMA to this memory
location, so you have to allocate it dynamically, sorry.
thanks,
greg k-h
next prev parent reply other threads:[~2013-02-22 19:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 18:07 [PATCH 2/2] staging: comedi: drivers: usbduxfast.c: fix for DMA buffers on stack Kumar Amit Mehta
2013-02-22 18:58 ` walter harms
2013-02-22 19:06 ` Greg KH [this message]
2013-02-23 15:59 ` walter harms
2013-02-23 17:34 ` Dan Carpenter
2013-02-23 18:13 ` walter harms
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=20130222190644.GA16011@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=fmhess@users.sourceforge.net \
--cc=gmate.amit@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wharms@bfs.de \
/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;
as well as URLs for NNTP newsgroup(s).