From: Dan Carpenter <dan.carpenter@oracle.com>
To: Kumar Amit Mehta <gmate.amit@gmail.com>
Cc: abbotti@mev.co.uk, devel@driverdev.osuosl.org,
fmhess@users.sourceforge.net, gregkh@linuxfoundation.org,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: comedi: drivers: usbduxsigma.c: fix DMA buffers on stack
Date: Thu, 21 Feb 2013 18:47:55 +0000 [thread overview]
Message-ID: <20130221184755.GG9138@mwanda> (raw)
In-Reply-To: <1361468826-12053-1-git-send-email-gmate.amit@gmail.com>
A couple small style issues.
On Thu, Feb 21, 2013 at 09:47:06AM -0800, Kumar Amit Mehta wrote:
> This patch fixes an instance of DMA buffer on stack(being passed to
> usb_control_msg)for the USB-DUXsigma Board driver. Found using smatch.
>
> Signed-off-by: Kumar Amit Mehta <gmate.amit@gmail.com>
> ---
> drivers/staging/comedi/drivers/usbduxsigma.c | 37 +++++++++++++++++---------
> 1 file changed, 24 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
> index dc6b017..46137e8 100644
> --- a/drivers/staging/comedi/drivers/usbduxsigma.c
> +++ b/drivers/staging/comedi/drivers/usbduxsigma.c
> @@ -681,10 +681,14 @@ static void usbduxsub_ao_IsocIrq(struct urb *urb)
> static int usbduxsub_start(struct usbduxsub *usbduxsub)
> {
> int errcode = 0;
> - uint8_t local_transfer_buffer[16];
> -
> + uint8_t *local_transfer_buffer;
Put a blank line here between the declaration and the code.
> + local_transfer_buffer = kmalloc(16, GFP_KERNEL);
> + if (!local_transfer_buffer) {
> + errcode = -ENOMEM;
> + goto exit;
Just return directly.
> + }
> /* 7f92 to zero */
> - local_transfer_buffer[0] = 0;
> + *local_transfer_buffer = 0;
The original is sort of nicer. local_transfer is an array and we're
setting the first element. It seems more clear to me. Also I
already had to argue with everyone to get comedi to use arrays
instead of pointer math. :P
I wonder why we have a 16 byte array when we only use the first
byte and we pass 1 as the length to usb_control_msg(). Odd.
Perhaps it shouldn't be an array after all.
regards,
dan carpenter
> static int usbduxsub_stop(struct usbduxsub *usbduxsub)
> {
> int errcode = 0;
>
Delete this blank line...
> - uint8_t local_transfer_buffer[16];
> + uint8_t *local_transfer_buffer;
> + local_transfer_buffer = kmalloc(16, GFP_KERNEL);
> + if (!local_transfer_buffer) {
> + errcode = -ENOMEM;
> + goto exit;
> + }
>
regards,
dan carpenter
prev parent reply other threads:[~2013-02-21 18:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-21 17:47 [PATCH] staging: comedi: drivers: usbduxsigma.c: fix DMA buffers on stack Kumar Amit Mehta
2013-02-21 18:47 ` Dan Carpenter [this message]
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=20130221184755.GG9138@mwanda \
--to=dan.carpenter@oracle.com \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=fmhess@users.sourceforge.net \
--cc=gmate.amit@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).